<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>

<meta charset="utf-8">
<meta name="generator" content="quarto-1.6.40">

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">


<title>Preparation of PSID Data</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
  width: 0.8em;
  margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */ 
  vertical-align: middle;
}
/* CSS for syntax highlighting */
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { display: inline-block; text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
  { counter-reset: source-line 0; }
pre.numberSource code > span
  { position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
  { content: counter(source-line);
    position: relative; left: -1em; text-align: right; vertical-align: baseline;
    border: none; display: inline-block;
    -webkit-touch-callout: none; -webkit-user-select: none;
    -khtml-user-select: none; -moz-user-select: none;
    -ms-user-select: none; user-select: none;
    padding: 0 4px; width: 4em;
  }
pre.numberSource { margin-left: 3em;  padding-left: 4px; }
div.sourceCode
  {   }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
</style>


<script src="clean_psid_data_files/libs/clipboard/clipboard.min.js"></script>
<script src="clean_psid_data_files/libs/quarto-html/quarto.js"></script>
<script src="clean_psid_data_files/libs/quarto-html/popper.min.js"></script>
<script src="clean_psid_data_files/libs/quarto-html/tippy.umd.min.js"></script>
<script src="clean_psid_data_files/libs/quarto-html/anchor.min.js"></script>
<link href="clean_psid_data_files/libs/quarto-html/tippy.css" rel="stylesheet">
<link href="clean_psid_data_files/libs/quarto-html/quarto-syntax-highlighting-549806ee2085284f45b00abea8c6df48.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="clean_psid_data_files/libs/bootstrap/bootstrap.min.js"></script>
<link href="clean_psid_data_files/libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="clean_psid_data_files/libs/bootstrap/bootstrap-973236bd072d72a04ee9cd82dcc9cb29.min.css" rel="stylesheet" append-hash="true" id="quarto-bootstrap" data-mode="light">

  <script src="https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js?features=es6"></script>
  <script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js" type="text/javascript"></script>

<script type="text/javascript">
const typesetMath = (el) => {
  if (window.MathJax) {
    // MathJax Typeset
    window.MathJax.typeset([el]);
  } else if (window.katex) {
    // KaTeX Render
    var mathElements = el.getElementsByClassName("math");
    var macros = [];
    for (var i = 0; i < mathElements.length; i++) {
      var texText = mathElements[i].firstChild;
      if (mathElements[i].tagName == "SPAN") {
        window.katex.render(texText.data, mathElements[i], {
          displayMode: mathElements[i].classList.contains('display'),
          throwOnError: false,
          macros: macros,
          fleqn: false
        });
      }
    }
  }
}
window.Quarto = {
  typesetMath
};
</script>

</head>

<body>

<div id="quarto-content" class="page-columns page-rows-contents page-layout-article">
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
  <nav id="TOC" role="doc-toc" class="toc-active">
    <h2 id="toc-title">Table of contents</h2>
   
  <ul>
  <li><a href="#introduction" id="toc-introduction" class="nav-link active" data-scroll-target="#introduction">Introduction</a>
  <ul class="collapse">
  <li><a href="#dependencies" id="toc-dependencies" class="nav-link" data-scroll-target="#dependencies">Dependencies</a></li>
  </ul></li>
  <li><a href="#arranging-main-interview-psid-data" id="toc-arranging-main-interview-psid-data" class="nav-link" data-scroll-target="#arranging-main-interview-psid-data">Arranging Main Interview PSID Data</a>
  <ul class="collapse">
  <li><a href="#identifiers-panel" id="toc-identifiers-panel" class="nav-link" data-scroll-target="#identifiers-panel">Identifiers Panel</a></li>
  <li><a href="#main-interview-childcare-expenditures" id="toc-main-interview-childcare-expenditures" class="nav-link" data-scroll-target="#main-interview-childcare-expenditures">Main Interview: Childcare Expenditures</a></li>
  <li><a href="#main-interview-state-of-residence" id="toc-main-interview-state-of-residence" class="nav-link" data-scroll-target="#main-interview-state-of-residence">Main Interview: State of Residence</a></li>
  <li><a href="#main-interview-parent-and-relative-location" id="toc-main-interview-parent-and-relative-location" class="nav-link" data-scroll-target="#main-interview-parent-and-relative-location">Main Interview: Parent and Relative Location</a></li>
  <li><a href="#main-interview-race" id="toc-main-interview-race" class="nav-link" data-scroll-target="#main-interview-race">Main Interview: Race</a></li>
  <li><a href="#main-interview-education" id="toc-main-interview-education" class="nav-link" data-scroll-target="#main-interview-education">Main Interview: Education</a></li>
  <li><a href="#main-interview-labor-market-data" id="toc-main-interview-labor-market-data" class="nav-link" data-scroll-target="#main-interview-labor-market-data">Main Interview: Labor Market Data</a></li>
  <li><a href="#main-interview-total-income" id="toc-main-interview-total-income" class="nav-link" data-scroll-target="#main-interview-total-income">Main Interview: Total Income</a></li>
  </ul></li>
  <li><a href="#arranging-psid-cds-data" id="toc-arranging-psid-cds-data" class="nav-link" data-scroll-target="#arranging-psid-cds-data">Arranging PSID-CDS Data</a>
  <ul class="collapse">
  <li><a href="#assessments" id="toc-assessments" class="nav-link" data-scroll-target="#assessments">Assessments</a></li>
  <li><a href="#time-diaries" id="toc-time-diaries" class="nav-link" data-scroll-target="#time-diaries">Time Diaries</a></li>
  <li><a href="#expenditures" id="toc-expenditures" class="nav-link" data-scroll-target="#expenditures">Expenditures</a>
  <ul class="collapse">
  <li><a href="#per-pupil-expenditures" id="toc-per-pupil-expenditures" class="nav-link" data-scroll-target="#per-pupil-expenditures">Per Pupil Expenditures</a></li>
  </ul></li>
  <li><a href="#childcare-expenditures" id="toc-childcare-expenditures" class="nav-link" data-scroll-target="#childcare-expenditures">Childcare Expenditures</a>
  <ul class="collapse">
  <li><a href="#collecting-data-for-younger-children" id="toc-collecting-data-for-younger-children" class="nav-link" data-scroll-target="#collecting-data-for-younger-children">Collecting Data for Younger Children</a></li>
  </ul></li>
  <li><a href="#age-by-month" id="toc-age-by-month" class="nav-link" data-scroll-target="#age-by-month">Age by Month</a></li>
  <li><a href="#staff-child-ratios" id="toc-staff-child-ratios" class="nav-link" data-scroll-target="#staff-child-ratios">Staff-child ratios</a></li>
  </ul></li>
  <li><a href="#assembling-a-panel-of-cds-mothers" id="toc-assembling-a-panel-of-cds-mothers" class="nav-link" data-scroll-target="#assembling-a-panel-of-cds-mothers">Assembling a Panel of CDS Mothers</a>
  <ul class="collapse">
  <li><a href="#making-a-panel-with-fertility-history" id="toc-making-a-panel-with-fertility-history" class="nav-link" data-scroll-target="#making-a-panel-with-fertility-history">Making a Panel with Fertility History</a></li>
  <li><a href="#merge-in-state-identifiers-and-childcare-expenditures" id="toc-merge-in-state-identifiers-and-childcare-expenditures" class="nav-link" data-scroll-target="#merge-in-state-identifiers-and-childcare-expenditures">Merge in State Identifiers and Childcare Expenditures</a></li>
  <li><a href="#identify-and-merge-in-spouses-fathers" id="toc-identify-and-merge-in-spouses-fathers" class="nav-link" data-scroll-target="#identify-and-merge-in-spouses-fathers">Identify and Merge in Spouses (“Fathers”)</a></li>
  <li><a href="#merge-in-spouse-birth-year-and-marriage-summary-variables" id="toc-merge-in-spouse-birth-year-and-marriage-summary-variables" class="nav-link" data-scroll-target="#merge-in-spouse-birth-year-and-marriage-summary-variables">Merge in Spouse Birth Year and Marriage Summary Variables</a></li>
  <li><a href="#merge-in-mothers-race-education-and-cpi-external" id="toc-merge-in-mothers-race-education-and-cpi-external" class="nav-link" data-scroll-target="#merge-in-mothers-race-education-and-cpi-external">Merge in Mother’s Race, Education, and CPI (external)</a></li>
  <li><a href="#clean-and-prepare-labor-market-data" id="toc-clean-and-prepare-labor-market-data" class="nav-link" data-scroll-target="#clean-and-prepare-labor-market-data">Clean and Prepare Labor Market Data</a></li>
  <li><a href="#merge-in-labor-market-earnings-hours-wages" id="toc-merge-in-labor-market-earnings-hours-wages" class="nav-link" data-scroll-target="#merge-in-labor-market-earnings-hours-wages">Merge in Labor Market Earnings, Hours, Wages</a></li>
  <li><a href="#sample-restrictions-and-creating-final-variables" id="toc-sample-restrictions-and-creating-final-variables" class="nav-link" data-scroll-target="#sample-restrictions-and-creating-final-variables">Sample restrictions and creating final variables</a></li>
  </ul></li>
  <li><a href="#assembling-a-panel-of-cds-children" id="toc-assembling-a-panel-of-cds-children" class="nav-link" data-scroll-target="#assembling-a-panel-of-cds-children">Assembling a Panel of CDS Children</a></li>
  </ul>
</nav>
</div>
<main class="content" id="quarto-document-content">

<header id="title-block-header" class="quarto-title-block default">
<div class="quarto-title">
<h1 class="title">Preparation of PSID Data</h1>
</div>



<div class="quarto-title-meta">

    
  
    
  </div>
  


</header>


<section id="introduction" class="level1">
<h1>Introduction</h1>
<p>This notebook contains code for transforming raw PSID data into the final datasets <code>MotherPanelCDS.csv</code> and <code>ChildPanelCDS.csv</code>.</p>
<section id="dependencies" class="level2">
<h2 class="anchored" data-anchor-id="dependencies">Dependencies</h2>
<p>The block of code below loads all the packages used in the process of doing this work.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(tidyverse)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.2     ✔ tibble    3.3.0
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.0.4     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (&lt;http://conflicted.r-lib.org/&gt;) to force all conflicts to become errors</code></pre>
</div>
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(foreign)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
</section>
<section id="arranging-main-interview-psid-data" class="level1">
<h1>Arranging Main Interview PSID Data</h1>
<section id="identifiers-panel" class="level2">
<h2 class="anchored" data-anchor-id="identifiers-panel">Identifiers Panel</h2>
<p>The main interview is administered at the household level, given by a survey year and an interview number (<code>intnum</code>). Here we make a panel linking each individual to an interview number in each survey year.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>D <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/main/identifiers/CrossYearIndex.xlsx"</span>)</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a>D <span class="ot">&lt;-</span> D[<span class="sc">-</span><span class="dv">1</span>]</span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a>index <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="st">"../../../data/data_PSID/main/identifiers/CrossYearIndex_labels.csv"</span>)</span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a><span class="fu">names</span>(index) <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"variable"</span>,<span class="st">"label"</span>,<span class="st">"year"</span>)</span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a>index<span class="sc">$</span>label <span class="ot">&lt;-</span> <span class="fu">str_c</span>(index<span class="sc">$</span>label,<span class="st">'_'</span>,index<span class="sc">$</span>year) </span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a>index <span class="ot">&lt;-</span> index[<span class="sc">-</span><span class="dv">3</span>]</span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a><span class="co">#everything should be renamed #&lt;- names</span></span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (i <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span><span class="fu">length</span>(D)){</span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true" tabindex="-1"></a>  <span class="fu">names</span>(D)[i] <span class="ot">=</span> <span class="fu">as.character</span>(index[[<span class="st">"label"</span>]][i])</span>
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb4-13"><a href="#cb4-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-14"><a href="#cb4-14" aria-hidden="true" tabindex="-1"></a>D <span class="ot">&lt;-</span> D <span class="sc">%&gt;%</span> <span class="fu">pivot_longer</span>(</span>
<span id="cb4-15"><a href="#cb4-15" aria-hidden="true" tabindex="-1"></a>  <span class="at">cols=</span><span class="sc">!</span><span class="fu">c</span>(in_1968,pn_1968),</span>
<span id="cb4-16"><a href="#cb4-16" aria-hidden="true" tabindex="-1"></a>  <span class="at">names_to =</span> <span class="fu">c</span>(<span class="st">"variable"</span>,<span class="st">"year"</span>),</span>
<span id="cb4-17"><a href="#cb4-17" aria-hidden="true" tabindex="-1"></a>  <span class="at">names_sep =</span> <span class="st">"_"</span>,</span>
<span id="cb4-18"><a href="#cb4-18" aria-hidden="true" tabindex="-1"></a>  <span class="at">values_to=</span><span class="st">"value"</span>)</span>
<span id="cb4-19"><a href="#cb4-19" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-20"><a href="#cb4-20" aria-hidden="true" tabindex="-1"></a>D <span class="ot">&lt;-</span> D <span class="sc">%&gt;%</span></span>
<span id="cb4-21"><a href="#cb4-21" aria-hidden="true" tabindex="-1"></a>  <span class="fu">pivot_wider</span>(<span class="at">names_from=</span>variable,<span class="at">values_from=</span>value) <span class="sc">%&gt;%</span></span>
<span id="cb4-22"><a href="#cb4-22" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="fu">as.integer</span>(year))</span>
<span id="cb4-23"><a href="#cb4-23" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-24"><a href="#cb4-24" aria-hidden="true" tabindex="-1"></a><span class="fu">names</span>(D) <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"intnum68"</span>,<span class="st">"pernum"</span>,<span class="st">"year"</span>,<span class="st">"relhead"</span>,</span>
<span id="cb4-25"><a href="#cb4-25" aria-hidden="true" tabindex="-1"></a>               <span class="st">"mpair"</span>,<span class="st">"intnum"</span>,<span class="st">"sn"</span>)</span>
<span id="cb4-26"><a href="#cb4-26" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-27"><a href="#cb4-27" aria-hidden="true" tabindex="-1"></a>D <span class="ot">&lt;-</span> D[,<span class="fu">c</span>(<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">3</span>,<span class="dv">6</span>,<span class="dv">7</span>,<span class="dv">4</span>,<span class="dv">5</span>)] <span class="sc">%&gt;%</span></span>
<span id="cb4-28"><a href="#cb4-28" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(<span class="sc">!</span><span class="fu">is.na</span>(intnum),intnum<span class="sc">&gt;</span><span class="dv">0</span>) <span class="co">#&lt;- drop observations where an individual cannot be merged to an interview. We don't need those.</span></span>
<span id="cb4-29"><a href="#cb4-29" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-30"><a href="#cb4-30" aria-hidden="true" tabindex="-1"></a>identifiers_panel <span class="ot">&lt;-</span> D</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="main-interview-childcare-expenditures" class="level2">
<h2 class="anchored" data-anchor-id="main-interview-childcare-expenditures">Main Interview: Childcare Expenditures</h2>
<p>Load the childcare data and arrange it into a panel at the <code>intnum</code> level.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a>D <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/main/expenditures/childcare/Main_childcare.xlsx"</span>)</span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a><span class="co"># these are all the years that the question is available</span></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a>years <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="fu">seq</span>(<span class="dv">1988</span>,<span class="dv">1997</span>),<span class="fu">seq</span>(<span class="dv">1999</span>,<span class="dv">2017</span>,<span class="dv">2</span>))</span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a>d <span class="ot">&lt;-</span> <span class="fu">data.frame</span>(<span class="at">year =</span> <span class="fu">integer</span>(), <span class="at">intnum =</span> <span class="fu">integer</span>(), <span class="at">childcare_exp =</span> <span class="fu">double</span>())</span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (i <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span><span class="fu">length</span>(years)) {</span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a>  d0 <span class="ot">&lt;-</span> <span class="fu">data.frame</span>(<span class="at">year =</span> years[i], <span class="at">intnum =</span> D[[(i<span class="dv">-1</span>)<span class="sc">*</span><span class="dv">3</span><span class="sc">+</span><span class="dv">2</span>]], <span class="at">childcare_exp =</span> D[[(i<span class="dv">-1</span>)<span class="sc">*</span><span class="dv">3</span><span class="sc">+</span><span class="dv">3</span>]])</span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a>  d <span class="ot">&lt;-</span> <span class="fu">rbind</span>(d,<span class="fu">na.omit</span>(d0))</span>
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb5-12"><a href="#cb5-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-13"><a href="#cb5-13" aria-hidden="true" tabindex="-1"></a><span class="co"># code up missing values</span></span>
<span id="cb5-14"><a href="#cb5-14" aria-hidden="true" tabindex="-1"></a>d<span class="sc">$</span>childcare_exp[(d<span class="sc">$</span>childcare_exp<span class="sc">&gt;=</span><span class="dv">99998</span>) <span class="sc">&amp;</span> d<span class="sc">$</span>year<span class="sc">&lt;</span><span class="dv">1999</span>] <span class="ot">&lt;-</span> <span class="cn">NA</span></span>
<span id="cb5-15"><a href="#cb5-15" aria-hidden="true" tabindex="-1"></a>d<span class="sc">$</span>childcare_exp[(d<span class="sc">$</span>childcare_exp<span class="sc">&gt;=</span><span class="dv">999998</span>)] <span class="ot">&lt;-</span> <span class="cn">NA</span></span>
<span id="cb5-16"><a href="#cb5-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-17"><a href="#cb5-17" aria-hidden="true" tabindex="-1"></a>main_childcare <span class="ot">&lt;-</span> d</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="main-interview-state-of-residence" class="level2">
<h2 class="anchored" data-anchor-id="main-interview-state-of-residence">Main Interview: State of Residence</h2>
<p>Load raw state of residence data and transform it into an <code>intnum</code> panel. Also loads a cross-walk from psid stat codes to FIPS and SOI.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>H <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="st">"../../../data/data_PSID/main/state/State.csv"</span>)</span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a>index2 <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="st">"../../../data/data_PSID/main/state/state-labels.csv"</span>,<span class="at">header=</span><span class="cn">FALSE</span>)</span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a><span class="fu">names</span>(index2) <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"variable"</span>,<span class="st">"label"</span>,<span class="st">"year"</span>)</span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a>index2<span class="sc">$</span>label <span class="ot">&lt;-</span> <span class="fu">str_c</span>(index2<span class="sc">$</span>label,<span class="st">'_'</span>,index2<span class="sc">$</span>year) </span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a>index2 <span class="ot">&lt;-</span> index2[<span class="sc">-</span><span class="dv">3</span>]</span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (i <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span><span class="fu">length</span>(H)){</span>
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true" tabindex="-1"></a>  <span class="fu">names</span>(H)[i] <span class="ot">=</span> <span class="fu">as.character</span>(index2[[<span class="st">"label"</span>]][i])</span>
<span id="cb6-10"><a href="#cb6-10" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb6-11"><a href="#cb6-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-12"><a href="#cb6-12" aria-hidden="true" tabindex="-1"></a>H <span class="ot">&lt;-</span> H <span class="sc">%&gt;%</span> <span class="fu">select</span>(<span class="sc">-</span><span class="fu">contains</span>(<span class="st">"relnum"</span>)) <span class="co">#dropping release num</span></span>
<span id="cb6-13"><a href="#cb6-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-14"><a href="#cb6-14" aria-hidden="true" tabindex="-1"></a>H <span class="ot">&lt;-</span> H <span class="sc">%&gt;%</span></span>
<span id="cb6-15"><a href="#cb6-15" aria-hidden="true" tabindex="-1"></a>  <span class="fu">pivot_longer</span>(<span class="at">cols=</span><span class="fu">everything</span>(),<span class="at">names_to =</span> <span class="fu">c</span>(<span class="st">".value"</span>,<span class="st">"year"</span>),<span class="at">names_sep =</span> <span class="st">"_"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb6-16"><a href="#cb6-16" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="fu">as.integer</span>(year)) <span class="sc">%&gt;%</span></span>
<span id="cb6-17"><a href="#cb6-17" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(<span class="sc">!</span><span class="fu">is.na</span>(intnum)) <span class="sc">%&gt;%</span></span>
<span id="cb6-18"><a href="#cb6-18" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(state<span class="sc">!=</span><span class="dv">0</span>,state<span class="sc">!=</span><span class="dv">99</span>) <span class="co">#&lt;- drop missing observations</span></span>
<span id="cb6-19"><a href="#cb6-19" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-20"><a href="#cb6-20" aria-hidden="true" tabindex="-1"></a>H <span class="ot">&lt;-</span> H[,<span class="fu">c</span>(<span class="dv">2</span>,<span class="dv">3</span>,<span class="dv">1</span>)]</span>
<span id="cb6-21"><a href="#cb6-21" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-22"><a href="#cb6-22" aria-hidden="true" tabindex="-1"></a>main_state <span class="ot">&lt;-</span> H</span>
<span id="cb6-23"><a href="#cb6-23" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-24"><a href="#cb6-24" aria-hidden="true" tabindex="-1"></a>state_codes <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="st">"../../../data/data_PSID/StateCodes.csv"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb6-25"><a href="#cb6-25" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">X =</span> <span class="cn">NULL</span>, <span class="at">X.1 =</span> <span class="cn">NULL</span>) <span class="sc">%&gt;%</span> <span class="co">#&lt;- this is a simple crosswalk of state codes</span></span>
<span id="cb6-26"><a href="#cb6-26" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(<span class="sc">-</span>state) <span class="sc">%&gt;%</span></span>
<span id="cb6-27"><a href="#cb6-27" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">state =</span> PSID, <span class="at">StFIPS =</span> fips) <span class="sc">%&gt;%</span> <span class="co">#&lt;- we rename some things in order to do the merge properly</span></span>
<span id="cb6-28"><a href="#cb6-28" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state, StFIPS, SOI, state_str)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="main-interview-parent-and-relative-location" class="level2">
<h2 class="anchored" data-anchor-id="main-interview-parent-and-relative-location">Main Interview: Parent and Relative Location</h2>
<p>Create a variable indicating if the individual still lives in the state they were born in.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="co"># ---- Measure 1: using an indicator for whether the individual is living in the state they grew up in</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a>years <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="dv">1968</span>,<span class="fu">seq</span>(<span class="dv">1969</span>,<span class="dv">1996</span>),<span class="fu">seq</span>(<span class="dv">1997</span>,<span class="dv">2019</span>,<span class="dv">2</span>))</span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a>d1 <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/main/parent-location/head_mobility.xlsx"</span>)</span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a><span class="co"># create a horizontal file:</span></span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true" tabindex="-1"></a>head_grow_up <span class="ot">=</span> <span class="fu">data.frame</span>() </span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (i <span class="cf">in</span> <span class="fu">seq</span>(<span class="dv">1</span><span class="sc">:</span><span class="fu">length</span>(years))) {</span>
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true" tabindex="-1"></a>  d <span class="ot">=</span> <span class="fu">data.frame</span>()</span>
<span id="cb7-10"><a href="#cb7-10" aria-hidden="true" tabindex="-1"></a>  <span class="co">#d$year &lt;- years[i]</span></span>
<span id="cb7-11"><a href="#cb7-11" aria-hidden="true" tabindex="-1"></a>  v_intnum <span class="ot">&lt;-</span> <span class="fu">names</span>(d1)[(i<span class="dv">-1</span>)<span class="sc">*</span><span class="dv">3</span><span class="sc">+</span><span class="dv">2</span>]</span>
<span id="cb7-12"><a href="#cb7-12" aria-hidden="true" tabindex="-1"></a>  d <span class="ot">&lt;-</span> d1[,v_intnum] <span class="sc">%&gt;%</span></span>
<span id="cb7-13"><a href="#cb7-13" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">intnum =</span> v_intnum)</span>
<span id="cb7-14"><a href="#cb7-14" aria-hidden="true" tabindex="-1"></a>  d<span class="sc">$</span>year <span class="ot">&lt;-</span> years[i]</span>
<span id="cb7-15"><a href="#cb7-15" aria-hidden="true" tabindex="-1"></a>  <span class="co">#d$intnum &lt;- d1[,v_intnum]</span></span>
<span id="cb7-16"><a href="#cb7-16" aria-hidden="true" tabindex="-1"></a>  v_loc <span class="ot">&lt;-</span> <span class="fu">names</span>(d1)[i<span class="sc">*</span><span class="dv">3</span>]</span>
<span id="cb7-17"><a href="#cb7-17" aria-hidden="true" tabindex="-1"></a>  d[,<span class="st">"state_grow_up"</span>]<span class="ot">&lt;-</span> d1[,v_loc]</span>
<span id="cb7-18"><a href="#cb7-18" aria-hidden="true" tabindex="-1"></a>  d <span class="ot">&lt;-</span> d <span class="sc">%&gt;%</span></span>
<span id="cb7-19"><a href="#cb7-19" aria-hidden="true" tabindex="-1"></a>    <span class="fu">drop_na</span>()</span>
<span id="cb7-20"><a href="#cb7-20" aria-hidden="true" tabindex="-1"></a>  head_grow_up <span class="ot">&lt;-</span> <span class="fu">rbind</span>(head_grow_up,d)</span>
<span id="cb7-21"><a href="#cb7-21" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Warning: Using an external vector in selections was deprecated in tidyselect 1.1.0.
ℹ Please use `all_of()` or `any_of()` instead.
  # Was:
  data %&gt;% select(v_intnum)

  # Now:
  data %&gt;% select(all_of(v_intnum))

See &lt;https://tidyselect.r-lib.org/reference/faq-external-vector.html&gt;.</code></pre>
</div>
<div class="sourceCode cell-code" id="cb9"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a>head_grow_up <span class="ot">&lt;-</span>  head_grow_up <span class="sc">%&gt;%</span></span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">state_grow_up=</span><span class="fu">na_if</span>(state_grow_up,<span class="dv">9</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Create a variable indicating the number of miles to parents.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb10"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="co"># ---- Measure 2: distance to parents in the 1988 main interview using a measure of distance from 1988:</span></span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a><span class="co"># load and clean the data</span></span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a><span class="co"># here we create a measure of whether either parent is within 10 miles or within 100 miles</span></span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a>parent_distance <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/main/parent-location/parent_distance.xlsx"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(                      </span>
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true" tabindex="-1"></a>         <span class="at">intnum =</span> V14802,<span class="co">#     1988 INTERVIEW NUMBER                   </span></span>
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true" tabindex="-1"></a>         <span class="at">head_miles_father =</span> V15816,     <span class="co"># OF MILES TO FATHER                    </span></span>
<span id="cb10-9"><a href="#cb10-9" aria-hidden="true" tabindex="-1"></a>         <span class="at">head_miles_mother =</span> V15830,     <span class="co"># OF MILES TO MOTHER                    </span></span>
<span id="cb10-10"><a href="#cb10-10" aria-hidden="true" tabindex="-1"></a>         <span class="at">sp_miles_father =</span> V15873,     <span class="co"># OF MILES TO FATHER-W                  </span></span>
<span id="cb10-11"><a href="#cb10-11" aria-hidden="true" tabindex="-1"></a>         <span class="at">sp_miles_mother =</span> V15887,     <span class="co"># OF MILES TO MOTHER-W                  </span></span>
<span id="cb10-12"><a href="#cb10-12" aria-hidden="true" tabindex="-1"></a>  ) <span class="sc">%&gt;%</span></span>
<span id="cb10-13"><a href="#cb10-13" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">head_ten_miles =</span> head_miles_father<span class="sc">&lt;=</span><span class="dv">2</span> <span class="sc">|</span> head_miles_mother<span class="sc">&lt;=</span><span class="dv">2</span>,</span>
<span id="cb10-14"><a href="#cb10-14" aria-hidden="true" tabindex="-1"></a>         <span class="at">head_hundred_miles =</span> head_miles_father<span class="sc">&lt;=</span><span class="dv">3</span> <span class="sc">|</span> head_miles_mother<span class="sc">&lt;=</span><span class="dv">3</span>,</span>
<span id="cb10-15"><a href="#cb10-15" aria-hidden="true" tabindex="-1"></a>         <span class="at">sp_ten_miles =</span> sp_miles_father<span class="sc">&lt;=</span><span class="dv">2</span> <span class="sc">|</span> sp_miles_mother<span class="sc">&lt;=</span><span class="dv">2</span>,</span>
<span id="cb10-16"><a href="#cb10-16" aria-hidden="true" tabindex="-1"></a>         <span class="at">sp_hundred_miles =</span> sp_miles_father<span class="sc">&lt;=</span><span class="dv">3</span> <span class="sc">|</span> sp_miles_mother<span class="sc">&lt;=</span><span class="dv">3</span>) <span class="sc">%&gt;%</span></span>
<span id="cb10-17"><a href="#cb10-17" aria-hidden="true" tabindex="-1"></a>  <span class="fu">drop_na</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Finally, an indicator for other relatives in the household.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb11"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a>relative_present <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="st">"../../../data/data_PSID/main/family_matrix/family_matrix.csv"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">KID=</span>MX5<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span>   MX6)<span class="sc">%&gt;%</span></span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a>  <span class="co">#indicator: there is an older relative (grandparent or uncle/aunt) in the HH</span></span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">biol_grand=</span><span class="fu">case_when</span>(MX8<span class="sc">==</span><span class="dv">60</span> <span class="sc">~</span> <span class="dv">1</span>,</span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a>                              <span class="co">#  MX8==94 ~ NA_real_,</span></span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a>                              <span class="cn">TRUE</span> <span class="sc">~</span> <span class="dv">0</span>))<span class="sc">%&gt;%</span></span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">older_relative=</span><span class="fu">case_when</span>(MX8<span class="sc">&gt;=</span><span class="dv">60</span> <span class="sc">&amp;</span> MX8<span class="sc">&lt;=</span><span class="dv">65</span> <span class="sc">~</span> <span class="dv">1</span>,</span>
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true" tabindex="-1"></a>                                  MX8<span class="sc">&gt;=</span><span class="dv">71</span> <span class="sc">&amp;</span> MX8<span class="sc">&lt;=</span><span class="dv">71</span> <span class="sc">~</span> <span class="dv">1</span>,</span>
<span id="cb11-9"><a href="#cb11-9" aria-hidden="true" tabindex="-1"></a>                                  MX8<span class="sc">&gt;=</span><span class="dv">80</span> <span class="sc">&amp;</span> MX8<span class="sc">&lt;=</span><span class="dv">81</span> <span class="sc">~</span> <span class="dv">1</span>,</span>
<span id="cb11-10"><a href="#cb11-10" aria-hidden="true" tabindex="-1"></a>                                  MX8<span class="sc">==</span><span class="dv">84</span> <span class="sc">~</span> <span class="dv">1</span>,</span>
<span id="cb11-11"><a href="#cb11-11" aria-hidden="true" tabindex="-1"></a>                                  <span class="co"># MX8==94 ~ NA_real_,</span></span>
<span id="cb11-12"><a href="#cb11-12" aria-hidden="true" tabindex="-1"></a>                                  <span class="cn">TRUE</span> <span class="sc">~</span> <span class="dv">0</span>))<span class="sc">%&gt;%</span></span>
<span id="cb11-13"><a href="#cb11-13" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(KID, year) <span class="sc">%&gt;%</span></span>
<span id="cb11-14"><a href="#cb11-14" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">older_relative_hh =</span> <span class="fu">max</span>(older_relative, <span class="at">na.rm =</span> <span class="cn">TRUE</span>), </span>
<span id="cb11-15"><a href="#cb11-15" aria-hidden="true" tabindex="-1"></a>         <span class="at">biol_grand_hh =</span> <span class="fu">max</span>(biol_grand, <span class="at">na.rm =</span> <span class="cn">TRUE</span>) )<span class="sc">%&gt;%</span></span>
<span id="cb11-16"><a href="#cb11-16" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(KID,year,older_relative_hh,  biol_grand_hh)<span class="sc">%&gt;%</span></span>
<span id="cb11-17"><a href="#cb11-17" aria-hidden="true" tabindex="-1"></a>  <span class="fu">distinct</span>(KID, year, <span class="at">.keep_all =</span> <span class="cn">TRUE</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="main-interview-race" class="level2">
<h2 class="anchored" data-anchor-id="main-interview-race">Main Interview: Race</h2>
<div class="cell">
<div class="sourceCode cell-code" id="cb12"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a>D <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/main/race/Race.xlsx"</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum =</span> V3)</span>
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb12-5"><a href="#cb12-5" aria-hidden="true" tabindex="-1"></a><span class="co"># let's create the data just by stacking</span></span>
<span id="cb12-6"><a href="#cb12-6" aria-hidden="true" tabindex="-1"></a><span class="co"># two blocks: years with just head, and years with</span></span>
<span id="cb12-7"><a href="#cb12-7" aria-hidden="true" tabindex="-1"></a>years1 <span class="ot">&lt;-</span> <span class="fu">seq</span>(<span class="dv">1969</span>,<span class="dv">1984</span>)</span>
<span id="cb12-8"><a href="#cb12-8" aria-hidden="true" tabindex="-1"></a>years2 <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="fu">seq</span>(<span class="dv">1985</span>,<span class="dv">1997</span>),<span class="fu">seq</span>(<span class="dv">1999</span>,<span class="dv">2017</span>,<span class="dv">2</span>))</span>
<span id="cb12-9"><a href="#cb12-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb12-10"><a href="#cb12-10" aria-hidden="true" tabindex="-1"></a><span class="co"># here are the variable names we want to use, copied and pasted</span></span>
<span id="cb12-11"><a href="#cb12-11" aria-hidden="true" tabindex="-1"></a><span class="co"># </span><span class="al">NOTE</span><span class="co">: we switched the order of head and spouse in 1985 (first appearance) in order to do things properly</span></span>
<span id="cb12-12"><a href="#cb12-12" aria-hidden="true" tabindex="-1"></a>vnames <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"V441"</span>   ,<span class="st">"V442"</span>   ,<span class="st">"V801"</span>   ,<span class="st">"V1101"</span>  ,<span class="st">"V1102"</span>  ,<span class="st">"V1490"</span>  ,<span class="st">"V1801"</span>  ,<span class="st">"V1802"</span>  ,<span class="st">"V2202"</span>  ,<span class="st">"V2401"</span>  ,<span class="st">"V2402"</span>  ,<span class="st">"V2828"</span>  ,<span class="st">"V3001"</span>  ,<span class="st">"V3002"</span>  ,<span class="st">"V3300"</span>  ,<span class="st">"V3401"</span>  ,<span class="st">"V3402"</span>  ,<span class="st">"V3720"</span>  ,<span class="st">"V3801"</span>  ,<span class="st">"V3802"</span>  ,<span class="st">"V4204"</span>  ,<span class="st">"V4301"</span>  ,<span class="st">"V4302"</span>  ,<span class="st">"V5096"</span>  ,<span class="st">"V5201"</span>  ,<span class="st">"V5202"</span>  ,<span class="st">"V5662"</span>  ,<span class="st">"V5701"</span>  ,<span class="st">"V5702"</span>  ,<span class="st">"V6209"</span>  ,<span class="st">"V6301"</span>  ,<span class="st">"V6302"</span>  ,<span class="st">"V6802"</span>  ,<span class="st">"V6901"</span>  ,<span class="st">"V6902"</span>  ,<span class="st">"V7447"</span>  ,<span class="st">"V7501"</span>  ,<span class="st">"V7502"</span>  ,<span class="st">"V8099"</span>  ,<span class="st">"V8201"</span>  ,<span class="st">"V8202"</span>  ,<span class="st">"V8723"</span>  ,<span class="st">"V8801"</span>  ,<span class="st">"V8802"</span>  ,<span class="st">"V9408"</span>  ,<span class="st">"V10001"</span> ,<span class="st">"V10002"</span> ,<span class="st">"V11055"</span> ,<span class="st">"V11101"</span> ,<span class="st">"V11102"</span> ,<span class="st">"V12293"</span> ,<span class="st">"V11938"</span> ,<span class="st">"V12501"</span> ,<span class="st">"V12502"</span> ,<span class="st">"V13500"</span> ,<span class="st">"V13565"</span> ,<span class="st">"V13701"</span> ,<span class="st">"V13702"</span> ,<span class="st">"V14547"</span> ,<span class="st">"V14612"</span> ,<span class="st">"V14801"</span> ,<span class="st">"V14802"</span> ,<span class="st">"V16021"</span> ,<span class="st">"V16086"</span> ,<span class="st">"V16301"</span> ,<span class="st">"V16302"</span> ,<span class="st">"V17418"</span> ,<span class="st">"V17483"</span> ,<span class="st">"V17701"</span> ,<span class="st">"V17702"</span> ,<span class="st">"V18749"</span> ,<span class="st">"V18814"</span> ,<span class="st">"V19001"</span> ,<span class="st">"V19002"</span> ,<span class="st">"V20049"</span> ,<span class="st">"V20114"</span> ,<span class="st">"V20301"</span> ,<span class="st">"V20302"</span> ,<span class="st">"V21355"</span> ,<span class="st">"V21420"</span> ,<span class="st">"V21601"</span> ,<span class="st">"V21602"</span> ,<span class="st">"V23212"</span> ,<span class="st">"V23276"</span> ,<span class="st">"ER2001"</span> ,<span class="st">"ER2002"</span> ,<span class="st">"ER3883"</span> ,<span class="st">"ER3944"</span> ,<span class="st">"ER5001"</span> ,<span class="st">"ER5002"</span> ,<span class="st">"ER6753"</span> ,<span class="st">"ER6814"</span> ,<span class="st">"ER7001"</span> ,<span class="st">"ER7002"</span> ,<span class="st">"ER8999"</span> ,<span class="st">"ER9060"</span> ,<span class="st">"ER10001"</span>,<span class="st">"ER10002"</span>,<span class="st">"ER11760"</span>,<span class="st">"ER11848"</span>,<span class="st">"ER13001"</span>,<span class="st">"ER13002"</span>,<span class="st">"ER15836"</span>,<span class="st">"ER15928"</span>,<span class="st">"ER17001"</span>,<span class="st">"ER17002"</span>,<span class="st">"ER19897"</span>,<span class="st">"ER19989"</span>,<span class="st">"ER21001"</span>,<span class="st">"ER21002"</span>,<span class="st">"ER23334"</span>,<span class="st">"ER23426"</span>,<span class="st">"ER25001"</span>,<span class="st">"ER25002"</span>,<span class="st">"ER27297"</span>,<span class="st">"ER27393"</span>,<span class="st">"ER36001"</span>,<span class="st">"ER36002"</span>,<span class="st">"ER40472"</span>,<span class="st">"ER40565"</span>,<span class="st">"ER42001"</span>,<span class="st">"ER42002"</span>,<span class="st">"ER46449"</span>,<span class="st">"ER46543"</span>,<span class="st">"ER47301"</span>,<span class="st">"ER47302"</span>,<span class="st">"ER51810"</span>,<span class="st">"ER51904"</span>,<span class="st">"ER53001"</span>,<span class="st">"ER53002"</span>,<span class="st">"ER57549"</span>,<span class="st">"ER57659"</span>,<span class="st">"ER60001"</span>,<span class="st">"ER60002"</span>,<span class="st">"ER64671"</span>,<span class="st">"ER64810"</span>,<span class="st">"ER66001"</span>,<span class="st">"ER66002"</span>,<span class="st">"ER70744"</span>,<span class="st">"ER70882"</span>)</span>
<span id="cb12-13"><a href="#cb12-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb12-14"><a href="#cb12-14" aria-hidden="true" tabindex="-1"></a>V <span class="ot">&lt;-</span> <span class="fu">data.frame</span>()</span>
<span id="cb12-15"><a href="#cb12-15" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb12-16"><a href="#cb12-16" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (i <span class="cf">in</span> <span class="fu">seq</span>(<span class="dv">1</span>,<span class="fu">length</span>(years1))) {</span>
<span id="cb12-17"><a href="#cb12-17" aria-hidden="true" tabindex="-1"></a>  v1 <span class="ot">=</span> vnames[(i<span class="dv">-1</span>)<span class="sc">*</span><span class="dv">3</span><span class="sc">+</span><span class="dv">2</span>]</span>
<span id="cb12-18"><a href="#cb12-18" aria-hidden="true" tabindex="-1"></a>  v2 <span class="ot">=</span> vnames[i<span class="sc">*</span><span class="dv">3</span>]</span>
<span id="cb12-19"><a href="#cb12-19" aria-hidden="true" tabindex="-1"></a>  d <span class="ot">&lt;-</span> <span class="fu">select</span>(D,<span class="fu">c</span>(v1,v2))</span>
<span id="cb12-20"><a href="#cb12-20" aria-hidden="true" tabindex="-1"></a>  d <span class="ot">&lt;-</span> <span class="fu">filter</span>(d,<span class="sc">!</span><span class="fu">is.na</span>(d[,v1]))</span>
<span id="cb12-21"><a href="#cb12-21" aria-hidden="true" tabindex="-1"></a>  <span class="fu">names</span>(d) <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"intnum"</span>,<span class="st">"race_head"</span>)</span>
<span id="cb12-22"><a href="#cb12-22" aria-hidden="true" tabindex="-1"></a>  d<span class="sc">$</span>year <span class="ot">&lt;-</span> years1[i]</span>
<span id="cb12-23"><a href="#cb12-23" aria-hidden="true" tabindex="-1"></a>  d<span class="sc">$</span>race_wife <span class="ot">&lt;-</span> <span class="cn">NA</span></span>
<span id="cb12-24"><a href="#cb12-24" aria-hidden="true" tabindex="-1"></a>  V <span class="ot">&lt;-</span> <span class="fu">rbind</span>(V,d)</span>
<span id="cb12-25"><a href="#cb12-25" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb12-26"><a href="#cb12-26" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb12-27"><a href="#cb12-27" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Warning: Using an external vector in selections was deprecated in tidyselect 1.1.0.
ℹ Please use `all_of()` or `any_of()` instead.
  # Was:
  data %&gt;% select(v1)

  # Now:
  data %&gt;% select(all_of(v1))

See &lt;https://tidyselect.r-lib.org/reference/faq-external-vector.html&gt;.</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>Warning: Using an external vector in selections was deprecated in tidyselect 1.1.0.
ℹ Please use `all_of()` or `any_of()` instead.
  # Was:
  data %&gt;% select(v2)

  # Now:
  data %&gt;% select(all_of(v2))

See &lt;https://tidyselect.r-lib.org/reference/faq-external-vector.html&gt;.</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>Warning: Using one column matrices in `filter()` was deprecated in dplyr 1.1.0.
ℹ Please use one dimensional logical vectors instead.</code></pre>
</div>
<div class="sourceCode cell-code" id="cb16"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (i <span class="cf">in</span> <span class="fu">seq</span>(<span class="dv">1</span>,<span class="fu">length</span>(years2))) {</span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a>  j <span class="ot">=</span> i <span class="sc">+</span> <span class="fu">length</span>(years1)</span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true" tabindex="-1"></a>  v1 <span class="ot">=</span> vnames[<span class="dv">48</span><span class="sc">+</span>(i<span class="dv">-1</span>)<span class="sc">*</span><span class="dv">4</span><span class="sc">+</span><span class="dv">2</span>]</span>
<span id="cb16-4"><a href="#cb16-4" aria-hidden="true" tabindex="-1"></a>  v2 <span class="ot">=</span> vnames[<span class="dv">48</span><span class="sc">+</span>(i<span class="dv">-1</span>)<span class="sc">*</span><span class="dv">4</span><span class="sc">+</span><span class="dv">3</span>]</span>
<span id="cb16-5"><a href="#cb16-5" aria-hidden="true" tabindex="-1"></a>  v3 <span class="ot">=</span> vnames[<span class="dv">48</span> <span class="sc">+</span> i<span class="sc">*</span><span class="dv">4</span>]</span>
<span id="cb16-6"><a href="#cb16-6" aria-hidden="true" tabindex="-1"></a>  d <span class="ot">&lt;-</span> <span class="fu">select</span>(D,<span class="fu">c</span>(v1,v3,v2))</span>
<span id="cb16-7"><a href="#cb16-7" aria-hidden="true" tabindex="-1"></a>  d <span class="ot">&lt;-</span> <span class="fu">filter</span>(d,<span class="sc">!</span><span class="fu">is.na</span>(d[,v1]))</span>
<span id="cb16-8"><a href="#cb16-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">names</span>(d) <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"intnum"</span>,<span class="st">"race_head"</span>,<span class="st">"race_wife"</span>)</span>
<span id="cb16-9"><a href="#cb16-9" aria-hidden="true" tabindex="-1"></a>  d<span class="sc">$</span>year <span class="ot">&lt;-</span> years2[i]</span>
<span id="cb16-10"><a href="#cb16-10" aria-hidden="true" tabindex="-1"></a>  V <span class="ot">&lt;-</span> <span class="fu">rbind</span>(V,d)</span>
<span id="cb16-11"><a href="#cb16-11" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb16-12"><a href="#cb16-12" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb16-13"><a href="#cb16-13" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Warning: Using an external vector in selections was deprecated in tidyselect 1.1.0.
ℹ Please use `all_of()` or `any_of()` instead.
  # Was:
  data %&gt;% select(v3)

  # Now:
  data %&gt;% select(all_of(v3))

See &lt;https://tidyselect.r-lib.org/reference/faq-external-vector.html&gt;.</code></pre>
</div>
<div class="sourceCode cell-code" id="cb18"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a>Ind <span class="ot">=</span> identifiers_panel <span class="sc">%&gt;%</span> </span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">ID =</span> intnum68<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> pernum) <span class="sc">%&gt;%</span></span>
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year<span class="sc">&lt;=</span><span class="dv">2011</span>) <span class="co">#&lt;- use only data from 2011 and earlier</span></span>
<span id="cb18-4"><a href="#cb18-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-5"><a href="#cb18-5" aria-hidden="true" tabindex="-1"></a>V <span class="ot">&lt;-</span> <span class="fu">merge</span>(V,Ind)</span>
<span id="cb18-6"><a href="#cb18-6" aria-hidden="true" tabindex="-1"></a>V<span class="sc">$</span>Race <span class="ot">&lt;-</span> <span class="cn">NA</span></span>
<span id="cb18-7"><a href="#cb18-7" aria-hidden="true" tabindex="-1"></a>V[V<span class="sc">$</span>sn<span class="sc">==</span><span class="dv">1</span>,<span class="st">"Race"</span>] <span class="ot">&lt;-</span> V[V<span class="sc">$</span>sn<span class="sc">==</span><span class="dv">1</span>,<span class="st">"race_head"</span>]</span>
<span id="cb18-8"><a href="#cb18-8" aria-hidden="true" tabindex="-1"></a>V[V<span class="sc">$</span>sn<span class="sc">==</span><span class="dv">2</span>,<span class="st">"Race"</span>] <span class="ot">&lt;-</span> V[V<span class="sc">$</span>sn<span class="sc">==</span><span class="dv">2</span>,<span class="st">"race_wife"</span>]</span>
<span id="cb18-9"><a href="#cb18-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-10"><a href="#cb18-10" aria-hidden="true" tabindex="-1"></a>D <span class="ot">&lt;-</span> V <span class="sc">%&gt;%</span></span>
<span id="cb18-11"><a href="#cb18-11" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(<span class="sc">!</span><span class="fu">is.na</span>(Race) <span class="sc">&amp;</span> Race<span class="sc">!=</span><span class="dv">0</span> <span class="sc">&amp;</span> Race<span class="sc">!=</span><span class="dv">9</span>) <span class="sc">%&gt;%</span></span>
<span id="cb18-12"><a href="#cb18-12" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(ID) <span class="sc">%&gt;%</span></span>
<span id="cb18-13"><a href="#cb18-13" aria-hidden="true" tabindex="-1"></a>  <span class="fu">arrange</span>(year) <span class="sc">%&gt;%</span></span>
<span id="cb18-14"><a href="#cb18-14" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(<span class="fu">row_number</span>()<span class="sc">==</span><span class="fu">n</span>()) <span class="sc">%&gt;%</span> <span class="co">#&lt;- keep the latest record</span></span>
<span id="cb18-15"><a href="#cb18-15" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(ID,Race)</span>
<span id="cb18-16"><a href="#cb18-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-17"><a href="#cb18-17" aria-hidden="true" tabindex="-1"></a>race <span class="ot">&lt;-</span> D</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="main-interview-education" class="level2">
<h2 class="anchored" data-anchor-id="main-interview-education">Main Interview: Education</h2>
<div class="cell">
<div class="sourceCode cell-code" id="cb19"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a>D <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/main/education/grades_completed.xlsx"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">ID =</span> ER30001<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> ER30002)</span>
<span id="cb19-3"><a href="#cb19-3" aria-hidden="true" tabindex="-1"></a>D1 <span class="ot">&lt;-</span> D[,<span class="fu">seq</span>(<span class="dv">5</span>,<span class="dv">158</span>,<span class="dv">4</span>)]</span>
<span id="cb19-4"><a href="#cb19-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb19-5"><a href="#cb19-5" aria-hidden="true" tabindex="-1"></a><span class="co"># this routine pulls out the most recent education variable, up to the year 2011.</span></span>
<span id="cb19-6"><a href="#cb19-6" aria-hidden="true" tabindex="-1"></a><span class="co"># the data itself go until 2017, but we only go up to 2011 to replicate the data used in first draft of CLMP</span></span>
<span id="cb19-7"><a href="#cb19-7" aria-hidden="true" tabindex="-1"></a>D<span class="sc">$</span>educ <span class="ot">&lt;-</span> <span class="sc">-</span><span class="dv">1</span></span>
<span id="cb19-8"><a href="#cb19-8" aria-hidden="true" tabindex="-1"></a>D<span class="sc">$</span>year_meas <span class="ot">&lt;-</span> <span class="sc">-</span><span class="dv">1</span></span>
<span id="cb19-9"><a href="#cb19-9" aria-hidden="true" tabindex="-1"></a>years <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="dv">1968</span>,<span class="fu">seq</span>(<span class="dv">1970</span>,<span class="dv">1996</span>),<span class="fu">seq</span>(<span class="dv">1997</span>,<span class="dv">2017</span>,<span class="dv">2</span>))</span>
<span id="cb19-10"><a href="#cb19-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb19-11"><a href="#cb19-11" aria-hidden="true" tabindex="-1"></a><span class="co"># replace with (i in 1:length(years)) if we want to update using measures from 2013-2017</span></span>
<span id="cb19-12"><a href="#cb19-12" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (i <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span><span class="dv">36</span>) {</span>
<span id="cb19-13"><a href="#cb19-13" aria-hidden="true" tabindex="-1"></a>  <span class="fu">print</span>(i)</span>
<span id="cb19-14"><a href="#cb19-14" aria-hidden="true" tabindex="-1"></a>  I_use <span class="ot">&lt;-</span> (D1[,i]<span class="sc">&gt;</span><span class="dv">0</span>) <span class="sc">&amp;</span> (D1[,i]<span class="sc">&lt;</span><span class="dv">98</span>)</span>
<span id="cb19-15"><a href="#cb19-15" aria-hidden="true" tabindex="-1"></a>  D[I_use,<span class="st">"educ"</span>] <span class="ot">&lt;-</span> D1[I_use,i]</span>
<span id="cb19-16"><a href="#cb19-16" aria-hidden="true" tabindex="-1"></a>  D[I_use,<span class="st">"year_meas"</span>] <span class="ot">&lt;-</span> years[i]</span>
<span id="cb19-17"><a href="#cb19-17" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
[1] 6
[1] 7
[1] 8
[1] 9
[1] 10
[1] 11
[1] 12
[1] 13
[1] 14
[1] 15
[1] 16
[1] 17
[1] 18
[1] 19
[1] 20
[1] 21
[1] 22
[1] 23
[1] 24
[1] 25
[1] 26
[1] 27
[1] 28
[1] 29
[1] 30
[1] 31
[1] 32
[1] 33
[1] 34
[1] 35
[1] 36</code></pre>
</div>
<div class="sourceCode cell-code" id="cb21"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a><span class="co"># do some final data cleaning and save the file</span></span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a>education <span class="ot">&lt;-</span> D <span class="sc">%&gt;%</span></span>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">educ =</span> <span class="fu">na_if</span>(educ,<span class="sc">-</span><span class="dv">1</span>), </span>
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a>         <span class="co">#ed=case_when(educ&gt;16 ~ 5,educ == 16 ~ 4, educ&gt;=13 ~ 3, educ&gt;=12 ~ 2, educ&lt;12 ~ 1)</span></span>
<span id="cb21-5"><a href="#cb21-5" aria-hidden="true" tabindex="-1"></a>         <span class="at">ed=</span><span class="fu">case_when</span>(educ<span class="sc">&gt;</span><span class="dv">16</span> <span class="sc">~</span> <span class="st">"&gt;16"</span>,educ <span class="sc">==</span> <span class="dv">16</span> <span class="sc">~</span> <span class="st">"16"</span>, educ<span class="sc">&gt;=</span><span class="dv">13</span> <span class="sc">~</span> <span class="st">"13-15"</span>, educ<span class="sc">&gt;=</span><span class="dv">12</span> <span class="sc">~</span> <span class="st">"12"</span>, educ<span class="sc">&lt;</span><span class="dv">12</span> <span class="sc">~</span> <span class="st">"&lt;12"</span>)</span>
<span id="cb21-6"><a href="#cb21-6" aria-hidden="true" tabindex="-1"></a>         ) <span class="sc">%&gt;%</span></span>
<span id="cb21-7"><a href="#cb21-7" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(ID,educ,ed,year_meas) <span class="sc">%&gt;%</span></span>
<span id="cb21-8"><a href="#cb21-8" aria-hidden="true" tabindex="-1"></a>  <span class="co">#mutate(ed = factor(ed,levels = c(1,2,3,4,5),labels=c("&lt;12","12","13-15","16","&gt;16"))) %&gt;%</span></span>
<span id="cb21-9"><a href="#cb21-9" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(ID,ed) <span class="co">#&lt;- just use this measure for now</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="main-interview-labor-market-data" class="level2">
<h2 class="anchored" data-anchor-id="main-interview-labor-market-data">Main Interview: Labor Market Data</h2>
<div class="cell">
<div class="sourceCode cell-code" id="cb22"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a>G <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/main/labor-market/earnings-hours.xlsx"</span>)</span>
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-3"><a href="#cb22-3" aria-hidden="true" tabindex="-1"></a>index1 <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="st">"../../../data/data_PSID/main/labor-market/earnings_labels_clean.csv"</span>,<span class="at">header=</span><span class="cn">FALSE</span>)</span>
<span id="cb22-4"><a href="#cb22-4" aria-hidden="true" tabindex="-1"></a><span class="fu">names</span>(index1) <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"variable"</span>,<span class="st">"label"</span>,<span class="st">"year"</span>)</span>
<span id="cb22-5"><a href="#cb22-5" aria-hidden="true" tabindex="-1"></a>index1<span class="sc">$</span>label <span class="ot">&lt;-</span> <span class="fu">str_c</span>(index1<span class="sc">$</span>label,<span class="st">'_'</span>,index1<span class="sc">$</span>year) </span>
<span id="cb22-6"><a href="#cb22-6" aria-hidden="true" tabindex="-1"></a>index1 <span class="ot">&lt;-</span> index1[<span class="sc">-</span><span class="dv">3</span>]</span>
<span id="cb22-7"><a href="#cb22-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-8"><a href="#cb22-8" aria-hidden="true" tabindex="-1"></a><span class="co">#everything should be renamed</span></span>
<span id="cb22-9"><a href="#cb22-9" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (i <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span><span class="fu">length</span>(G)){</span>
<span id="cb22-10"><a href="#cb22-10" aria-hidden="true" tabindex="-1"></a>  <span class="fu">names</span>(G)[i] <span class="ot">=</span> <span class="fu">as.character</span>(index1[[<span class="st">"label"</span>]][i])</span>
<span id="cb22-11"><a href="#cb22-11" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb22-12"><a href="#cb22-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-13"><a href="#cb22-13" aria-hidden="true" tabindex="-1"></a>G <span class="ot">&lt;-</span> G <span class="sc">%&gt;%</span> <span class="fu">select</span>(<span class="sc">-</span><span class="fu">contains</span>(<span class="st">"relnum"</span>)) <span class="sc">%&gt;%</span> <span class="co">#dropping the relnum columns</span></span>
<span id="cb22-14"><a href="#cb22-14" aria-hidden="true" tabindex="-1"></a>  <span class="fu">pivot_longer</span>(<span class="at">cols=</span><span class="fu">everything</span>(),<span class="at">names_to =</span> <span class="fu">c</span>(<span class="st">".value"</span>,<span class="st">"year"</span>),<span class="at">names_sep =</span> <span class="st">"_"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb22-15"><a href="#cb22-15" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(<span class="sc">!</span><span class="fu">is.na</span>(intnum)) <span class="sc">%&gt;%</span></span>
<span id="cb22-16"><a href="#cb22-16" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="fu">as.integer</span>(year))</span>
<span id="cb22-17"><a href="#cb22-17" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-18"><a href="#cb22-18" aria-hidden="true" tabindex="-1"></a>G[<span class="fu">c</span>(<span class="st">"earnspousebusiness"</span>)][<span class="fu">is.na</span>(G[<span class="fu">c</span>(<span class="st">"earnspousebusiness"</span>)])] <span class="ot">&lt;-</span> <span class="dv">0</span></span>
<span id="cb22-19"><a href="#cb22-19" aria-hidden="true" tabindex="-1"></a><span class="co">#replaces NA business earnings with 0</span></span>
<span id="cb22-20"><a href="#cb22-20" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-21"><a href="#cb22-21" aria-hidden="true" tabindex="-1"></a><span class="fu">names</span>(G) <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"year"</span>,<span class="st">"intnum"</span>,<span class="st">"hours_head"</span>,<span class="st">"hours_spouse"</span>,</span>
<span id="cb22-22"><a href="#cb22-22" aria-hidden="true" tabindex="-1"></a>              <span class="st">"earn_head"</span>,<span class="st">"earn_spouse"</span>,<span class="st">"earn_spouseBusiness"</span>)</span>
<span id="cb22-23"><a href="#cb22-23" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-24"><a href="#cb22-24" aria-hidden="true" tabindex="-1"></a>G <span class="ot">&lt;-</span> G[,<span class="fu">c</span>(<span class="dv">2</span>,<span class="dv">1</span>,<span class="dv">5</span>,<span class="dv">6</span>,<span class="dv">3</span>,<span class="dv">4</span>,<span class="dv">7</span>)]</span>
<span id="cb22-25"><a href="#cb22-25" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-26"><a href="#cb22-26" aria-hidden="true" tabindex="-1"></a><span class="do">##crude way to remove the variables we don't want, I was checking sequentially</span></span>
<span id="cb22-27"><a href="#cb22-27" aria-hidden="true" tabindex="-1"></a>G <span class="ot">&lt;-</span> G[<span class="sc">!</span>(G<span class="sc">$</span>year<span class="sc">==</span><span class="dv">1993</span> <span class="sc">&amp;</span> G<span class="sc">$</span>hours_head<span class="sc">==</span><span class="dv">9999</span>),] </span>
<span id="cb22-28"><a href="#cb22-28" aria-hidden="true" tabindex="-1"></a>G <span class="ot">&lt;-</span> G[<span class="sc">!</span>(G<span class="sc">$</span>year<span class="sc">==</span><span class="dv">1993</span> <span class="sc">&amp;</span> G<span class="sc">$</span>hours_spouse<span class="sc">==</span><span class="dv">6730</span>),]</span>
<span id="cb22-29"><a href="#cb22-29" aria-hidden="true" tabindex="-1"></a>G <span class="ot">&lt;-</span> G[<span class="sc">!</span>(G<span class="sc">$</span>year<span class="sc">==</span><span class="dv">1993</span> <span class="sc">&amp;</span> G<span class="sc">$</span>hours_spouse<span class="sc">==</span><span class="dv">9999</span>),] </span>
<span id="cb22-30"><a href="#cb22-30" aria-hidden="true" tabindex="-1"></a>G <span class="ot">&lt;-</span> G[<span class="sc">!</span>(G<span class="sc">$</span>year<span class="sc">==</span><span class="dv">1993</span> <span class="sc">&amp;</span> G<span class="sc">$</span>earn_head<span class="sc">==</span><span class="dv">99999999</span>),] </span>
<span id="cb22-31"><a href="#cb22-31" aria-hidden="true" tabindex="-1"></a>G <span class="ot">&lt;-</span> G[<span class="sc">!</span>(G<span class="sc">$</span>year<span class="sc">==</span><span class="dv">1994</span> <span class="sc">&amp;</span> G<span class="sc">$</span>hours_head<span class="sc">==</span><span class="dv">9999</span>),]</span>
<span id="cb22-32"><a href="#cb22-32" aria-hidden="true" tabindex="-1"></a>G <span class="ot">&lt;-</span> G[<span class="sc">!</span>(G<span class="sc">$</span>year<span class="sc">==</span><span class="dv">1994</span> <span class="sc">&amp;</span> G<span class="sc">$</span>hours_spouse<span class="sc">==</span><span class="dv">9999</span>),]</span>
<span id="cb22-33"><a href="#cb22-33" aria-hidden="true" tabindex="-1"></a>G <span class="ot">&lt;-</span> G[<span class="sc">!</span>(G<span class="sc">$</span>year<span class="sc">==</span><span class="dv">1994</span> <span class="sc">&amp;</span> G<span class="sc">$</span>earn_head<span class="sc">==</span><span class="dv">9999999</span>),]</span>
<span id="cb22-34"><a href="#cb22-34" aria-hidden="true" tabindex="-1"></a>G <span class="ot">&lt;-</span> G[<span class="sc">!</span>(G<span class="sc">$</span>year<span class="sc">==</span><span class="dv">1994</span> <span class="sc">&amp;</span> G<span class="sc">$</span>earn_spouseBusiness<span class="sc">==</span><span class="dv">999999</span>),]</span>
<span id="cb22-35"><a href="#cb22-35" aria-hidden="true" tabindex="-1"></a>G <span class="ot">&lt;-</span> G[<span class="sc">!</span>(G<span class="sc">$</span>year<span class="sc">==</span><span class="dv">1994</span> <span class="sc">&amp;</span> G<span class="sc">$</span>earn_spouse<span class="sc">==</span><span class="dv">9999999</span>),]</span>
<span id="cb22-36"><a href="#cb22-36" aria-hidden="true" tabindex="-1"></a>G <span class="ot">&lt;-</span> G[<span class="sc">!</span>(G<span class="sc">$</span>year<span class="sc">==</span><span class="dv">1995</span> <span class="sc">&amp;</span> G<span class="sc">$</span>hours_head<span class="sc">==</span><span class="dv">7800</span>),]</span>
<span id="cb22-37"><a href="#cb22-37" aria-hidden="true" tabindex="-1"></a>G <span class="ot">&lt;-</span> G[<span class="sc">!</span>(G<span class="sc">$</span>year<span class="sc">==</span><span class="dv">1995</span> <span class="sc">&amp;</span> G<span class="sc">$</span>earn_head<span class="sc">==</span><span class="dv">9999999</span>),]</span>
<span id="cb22-38"><a href="#cb22-38" aria-hidden="true" tabindex="-1"></a>G <span class="ot">&lt;-</span> G[<span class="sc">!</span>(G<span class="sc">$</span>year<span class="sc">==</span><span class="dv">1995</span> <span class="sc">&amp;</span> G<span class="sc">$</span>earn_spouse<span class="sc">==</span><span class="dv">9999999</span>),]</span>
<span id="cb22-39"><a href="#cb22-39" aria-hidden="true" tabindex="-1"></a>G <span class="ot">&lt;-</span> G[<span class="sc">!</span>(G<span class="sc">$</span>year<span class="sc">==</span><span class="dv">1996</span> <span class="sc">&amp;</span> G<span class="sc">$</span>hours_spouse<span class="sc">==</span><span class="dv">999999</span>),]</span>
<span id="cb22-40"><a href="#cb22-40" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-41"><a href="#cb22-41" aria-hidden="true" tabindex="-1"></a>earnings_panel <span class="ot">&lt;-</span> G</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Now we clean data from the T2 supplement:</p>
<p>Since the PSID went to a biennial format after 1997, the file <em>LaborFile.csv</em> does not have data for 1998,2000, and so on. A supplementary set of questions is asked about the family members from the previous year. These are sometimes called the “T2” supplement, which the chunk of code below cleans into a panel dataset for those missing years. These data were collected from the “Individual Data Index” from the PSID’s data center tool, so they are linked to individuals already. The code below renames the variables and reshapes them into a panel. The reporting of earnings in these years is slightly different from the main questions, so we keep only observations that are reported in annual terms (the large majority). There is also an abnormally large increase in the number of individuals who report zero hours but positive earnings from 2001 and on. We have to correct for this using the T2 variables from the main interview file.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb23"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a><span class="co">#changes: add T2 income variables from the individual fils : available up to 2007, no calculated hourly wage after 2001</span></span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a><span class="co">#changes: add T2 income variables from the family: merge using ID in 2009</span></span>
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true" tabindex="-1"></a><span class="co">#ifif hrs and earnings positive - use earnings : why so many zero wages?</span></span>
<span id="cb23-4"><a href="#cb23-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-5"><a href="#cb23-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-6"><a href="#cb23-6" aria-hidden="true" tabindex="-1"></a>Dt2 <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/main/labor-market/T2_97_07.xlsx"</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb23-7"><a href="#cb23-7" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">MID =</span> ER30001<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> ER30002,<span class="at">FID =</span> MID) <span class="sc">%&gt;%</span></span>
<span id="cb23-8"><a href="#cb23-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">earn97 =</span> ER33536A,<span class="at">earn99 =</span> ER33627A,<span class="at">earn01 =</span> ER33727A) <span class="sc">%&gt;%</span></span>
<span id="cb23-9"><a href="#cb23-9" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">earn97u =</span> ER33536B,<span class="at">earn99u =</span> ER33627B,<span class="at">earn01u =</span> ER33727B) <span class="sc">%&gt;%</span></span>
<span id="cb23-10"><a href="#cb23-10" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">wage97 =</span> ER33537O,<span class="at">wage99 =</span> ER33628O,<span class="at">wage01 =</span> ER33728O) <span class="sc">%&gt;%</span></span>
<span id="cb23-11"><a href="#cb23-11" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">ww97 =</span> ER33536C,<span class="at">ww99 =</span> ER33627C,<span class="at">ww01 =</span> ER33727C) <span class="sc">%&gt;%</span></span>
<span id="cb23-12"><a href="#cb23-12" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">hw97 =</span> ER33536Q,<span class="at">hw99 =</span> ER33627Q,<span class="at">hw01 =</span> ER33727Q)<span class="sc">%&gt;%</span></span>
<span id="cb23-13"><a href="#cb23-13" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">earn03 =</span> ER33826A,<span class="at">earn05 =</span> ER33926A) <span class="sc">%&gt;%</span></span>
<span id="cb23-14"><a href="#cb23-14" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">earn03u =</span> ER33826B ,<span class="at">earn05u =</span> ER33926B) <span class="sc">%&gt;%</span></span>
<span id="cb23-15"><a href="#cb23-15" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">hw03 =</span> ER33827U, <span class="at">hw05 =</span> ER33927C ) <span class="sc">%&gt;%</span></span>
<span id="cb23-16"><a href="#cb23-16" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">ww03 =</span> ER33827S , <span class="at">ww05 =</span> ER33927A  )</span>
<span id="cb23-17"><a href="#cb23-17" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-18"><a href="#cb23-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-19"><a href="#cb23-19" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-20"><a href="#cb23-20" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb23-21"><a href="#cb23-21" aria-hidden="true" tabindex="-1"></a><span class="co"># let's just do these for now</span></span>
<span id="cb23-22"><a href="#cb23-22" aria-hidden="true" tabindex="-1"></a>D97 <span class="ot">&lt;-</span> Dt2 <span class="sc">%&gt;%</span> <span class="fu">select</span>(MID,FID,earn97,earn97u,wage97,ww97,hw97) <span class="sc">%&gt;%</span></span>
<span id="cb23-23"><a href="#cb23-23" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">earn=</span>earn97,<span class="at">earnu=</span>earn97u,<span class="at">wage=</span>wage97,<span class="at">ww=</span>ww97,<span class="at">hw=</span>hw97) <span class="sc">%&gt;%</span></span>
<span id="cb23-24"><a href="#cb23-24" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year=</span><span class="dv">1997</span>)</span>
<span id="cb23-25"><a href="#cb23-25" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-26"><a href="#cb23-26" aria-hidden="true" tabindex="-1"></a>D99 <span class="ot">&lt;-</span> Dt2 <span class="sc">%&gt;%</span> <span class="fu">select</span>(MID,FID,earn99,earn99u,wage99,ww99,hw99) <span class="sc">%&gt;%</span></span>
<span id="cb23-27"><a href="#cb23-27" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">earn=</span>earn99,<span class="at">earnu=</span>earn99u,<span class="at">wage=</span>wage99,<span class="at">ww=</span>ww99,<span class="at">hw=</span>hw99) <span class="sc">%&gt;%</span></span>
<span id="cb23-28"><a href="#cb23-28" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year=</span><span class="dv">1999</span>)</span>
<span id="cb23-29"><a href="#cb23-29" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-30"><a href="#cb23-30" aria-hidden="true" tabindex="-1"></a>D01 <span class="ot">&lt;-</span> Dt2 <span class="sc">%&gt;%</span> <span class="fu">select</span>(MID,FID,earn01,earn01u,wage01,ww01,hw01) <span class="sc">%&gt;%</span></span>
<span id="cb23-31"><a href="#cb23-31" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">earn=</span>earn01,<span class="at">earnu=</span>earn01u,<span class="at">wage=</span>wage01,<span class="at">ww=</span>ww01,<span class="at">hw=</span>hw01) <span class="sc">%&gt;%</span></span>
<span id="cb23-32"><a href="#cb23-32" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year=</span><span class="dv">2001</span>)</span>
<span id="cb23-33"><a href="#cb23-33" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-34"><a href="#cb23-34" aria-hidden="true" tabindex="-1"></a>D03 <span class="ot">&lt;-</span> Dt2 <span class="sc">%&gt;%</span> <span class="fu">select</span>(MID,FID,earn03,earn03u,ww03,hw03) <span class="sc">%&gt;%</span></span>
<span id="cb23-35"><a href="#cb23-35" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">earn=</span>earn03,<span class="at">earnu=</span>earn03u,<span class="at">ww=</span>ww03,<span class="at">hw=</span>hw03) <span class="sc">%&gt;%</span></span>
<span id="cb23-36"><a href="#cb23-36" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year=</span><span class="dv">2003</span>)</span>
<span id="cb23-37"><a href="#cb23-37" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-38"><a href="#cb23-38" aria-hidden="true" tabindex="-1"></a>D05 <span class="ot">&lt;-</span> Dt2 <span class="sc">%&gt;%</span> <span class="fu">select</span>(MID,FID,earn05,earn05u,ww05,hw05) <span class="sc">%&gt;%</span></span>
<span id="cb23-39"><a href="#cb23-39" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">earn=</span>earn05,<span class="at">earnu=</span>earn05u,<span class="at">ww=</span>ww05,<span class="at">hw=</span>hw05) <span class="sc">%&gt;%</span></span>
<span id="cb23-40"><a href="#cb23-40" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year=</span><span class="dv">2005</span>)</span>
<span id="cb23-41"><a href="#cb23-41" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-42"><a href="#cb23-42" aria-hidden="true" tabindex="-1"></a><span class="co"># --- Now, read in the T-2 in 2001 variables from the family file</span></span>
<span id="cb23-43"><a href="#cb23-43" aria-hidden="true" tabindex="-1"></a>Dt01 <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="st">"../../../data/data_PSID/main/labor-market/T2_supp.csv"</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb23-44"><a href="#cb23-44" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum =</span> ER21002,<span class="at">h_earn =</span> ER23702F1,<span class="at">h_ww =</span> ER23702D3,<span class="at">h_hw =</span> ER23702E8) <span class="sc">%&gt;%</span></span>
<span id="cb23-45"><a href="#cb23-45" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">w_earn =</span> ER23702L4, <span class="at">w_ww =</span> ER23702J6, <span class="at">w_hw =</span> ER23702L2) <span class="sc">%&gt;%</span></span>
<span id="cb23-46"><a href="#cb23-46" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">2003</span>)</span>
<span id="cb23-47"><a href="#cb23-47" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-48"><a href="#cb23-48" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-49"><a href="#cb23-49" aria-hidden="true" tabindex="-1"></a><span class="co">#Doownload variables from family files separately from individual files - smaller datasets</span></span>
<span id="cb23-50"><a href="#cb23-50" aria-hidden="true" tabindex="-1"></a><span class="co"># --- Read in the T-2 from family file in 2003</span></span>
<span id="cb23-51"><a href="#cb23-51" aria-hidden="true" tabindex="-1"></a>Dt03 <span class="ot">=</span>  readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/main/labor-market/T2.xlsx"</span>)<span class="sc">%&gt;%</span> <span class="co">#2005 family interview number , 2003 earnings</span></span>
<span id="cb23-52"><a href="#cb23-52" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum =</span> ER25002,<span class="at">h_earn =</span> ER27711F1,<span class="at">h_ww =</span> ER27711D3,<span class="at">h_hw =</span> ER27711E8, <span class="at">h_earnu=</span>ER27711F2) <span class="sc">%&gt;%</span></span>
<span id="cb23-53"><a href="#cb23-53" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">w_earn =</span> ER27711L4, <span class="at">w_ww =</span> ER27711J6  , <span class="at">w_hw =</span> ER27711L2, <span class="at">w_earnu=</span> ER27711L5) <span class="sc">%&gt;%</span></span>
<span id="cb23-54"><a href="#cb23-54" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">2005</span>) <span class="sc">%&gt;%</span></span>
<span id="cb23-55"><a href="#cb23-55" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(year, intnum, h_earn,h_ww,h_hw,h_earnu,w_earn,w_ww,w_hw,w_earnu)<span class="sc">%&gt;%</span></span>
<span id="cb23-56"><a href="#cb23-56" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(<span class="fu">is.na</span>(intnum)<span class="sc">==</span><span class="dv">0</span>)</span>
<span id="cb23-57"><a href="#cb23-57" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-58"><a href="#cb23-58" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-59"><a href="#cb23-59" aria-hidden="true" tabindex="-1"></a>Dt05 <span class="ot">=</span>  readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/main/labor-market/T2.xlsx"</span>)<span class="sc">%&gt;%</span> <span class="co">#2007 family interview number, 2005 earnings</span></span>
<span id="cb23-60"><a href="#cb23-60" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum =</span> ER36002,<span class="at">h_earn =</span> ER40686F1,<span class="at">h_ww =</span> ER40686D3,<span class="at">h_hw =</span> ER40686E8 , <span class="at">h_earnu=</span>ER40686F2) <span class="sc">%&gt;%</span></span>
<span id="cb23-61"><a href="#cb23-61" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">w_earn =</span> ER40686L4, <span class="at">w_ww =</span>  ER40686J6 , <span class="at">w_hw =</span> ER40686L2, <span class="at">w_earnu=</span> ER40686L5 ) <span class="sc">%&gt;%</span></span>
<span id="cb23-62"><a href="#cb23-62" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">2007</span>) <span class="sc">%&gt;%</span> <span class="fu">select</span>(year, intnum, h_earn,h_ww,h_hw,h_earnu,w_earn,w_ww,w_hw,w_earnu)<span class="sc">%&gt;%</span> </span>
<span id="cb23-63"><a href="#cb23-63" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(<span class="fu">is.na</span>(intnum)<span class="sc">==</span><span class="dv">0</span>)</span>
<span id="cb23-64"><a href="#cb23-64" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-65"><a href="#cb23-65" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-66"><a href="#cb23-66" aria-hidden="true" tabindex="-1"></a><span class="co"># --- Read in the T-2 in 2007 for household heads and wives #2009 family interview number, 2007 earnings</span></span>
<span id="cb23-67"><a href="#cb23-67" aria-hidden="true" tabindex="-1"></a>Dt07 <span class="ot">=</span>  readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/main/labor-market/T2.xlsx"</span>)<span class="sc">%&gt;%</span></span>
<span id="cb23-68"><a href="#cb23-68" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum =</span> ER42002 ,<span class="at">h_earn =</span> ER46673,<span class="at">h_ww =</span> ER46670 ,<span class="at">h_hw =</span> ER46671 , <span class="at">h_earnu=</span>ER46674 ) <span class="sc">%&gt;%</span></span>
<span id="cb23-69"><a href="#cb23-69" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">w_earn =</span> ER46684, <span class="at">w_ww =</span> ER46681   , <span class="at">w_hw =</span> ER46682 , <span class="at">w_earnu=</span> ER46685 ) <span class="sc">%&gt;%</span></span>
<span id="cb23-70"><a href="#cb23-70" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">2009</span>) <span class="sc">%&gt;%</span> <span class="fu">select</span>(year, intnum, h_earn,h_ww,h_hw,h_earnu,w_earn,w_ww,w_hw,w_earnu) <span class="sc">%&gt;%</span> </span>
<span id="cb23-71"><a href="#cb23-71" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(<span class="fu">is.na</span>(intnum)<span class="sc">==</span><span class="dv">0</span>)</span>
<span id="cb23-72"><a href="#cb23-72" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-73"><a href="#cb23-73" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-74"><a href="#cb23-74" aria-hidden="true" tabindex="-1"></a><span class="co"># --- Read in the T-2 in 2009 for household heads and wives #2011 family interview number, 2009 earnings</span></span>
<span id="cb23-75"><a href="#cb23-75" aria-hidden="true" tabindex="-1"></a>Dt09 <span class="ot">=</span>  readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/main/labor-market/T2.xlsx"</span>)<span class="sc">%&gt;%</span></span>
<span id="cb23-76"><a href="#cb23-76" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum =</span> ER47302 ,<span class="at">h_earn =</span> ER52074 ,<span class="at">h_ww =</span> ER52071 ,<span class="at">h_hw =</span> ER52072 , <span class="at">h_earnu=</span> ER52075 ) <span class="sc">%&gt;%</span></span>
<span id="cb23-77"><a href="#cb23-77" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">w_earn =</span> ER52085, <span class="at">w_ww =</span> ER52082   , <span class="at">w_hw =</span> ER52083 , <span class="at">w_earnu=</span> ER52086 ) <span class="sc">%&gt;%</span></span>
<span id="cb23-78"><a href="#cb23-78" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">2011</span>) <span class="sc">%&gt;%</span> <span class="fu">select</span>(year, intnum, h_earn,h_ww,h_hw,h_earnu,w_earn,w_ww,w_hw,w_earnu)<span class="sc">%&gt;%</span> </span>
<span id="cb23-79"><a href="#cb23-79" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(<span class="fu">is.na</span>(intnum)<span class="sc">==</span><span class="dv">0</span>)</span>
<span id="cb23-80"><a href="#cb23-80" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-81"><a href="#cb23-81" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-82"><a href="#cb23-82" aria-hidden="true" tabindex="-1"></a><span class="co"># --- Read in the T-2 in 2011 for household heads and wives #2013 family interview number, 2011 earnings</span></span>
<span id="cb23-83"><a href="#cb23-83" aria-hidden="true" tabindex="-1"></a>Dt11 <span class="ot">=</span>   readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/main/labor-market/T2.xlsx"</span>)<span class="sc">%&gt;%</span></span>
<span id="cb23-84"><a href="#cb23-84" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum =</span> ER53002 ,<span class="at">h_earn =</span> ER57841 ,<span class="at">h_ww =</span> ER57825 ,<span class="at">h_hw =</span> ER57839 , <span class="at">h_earnu=</span> ER57842 ) <span class="sc">%&gt;%</span></span>
<span id="cb23-85"><a href="#cb23-85" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">w_earn =</span> ER57889, <span class="at">w_ww =</span> ER57873  , <span class="at">w_hw =</span> ER57887  , <span class="at">w_earnu=</span> ER57890 ) <span class="sc">%&gt;%</span></span>
<span id="cb23-86"><a href="#cb23-86" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">2013</span>) <span class="sc">%&gt;%</span> <span class="fu">select</span>(year, intnum, h_earn,h_ww,h_hw,h_earnu,w_earn,w_ww,w_hw,w_earnu)<span class="sc">%&gt;%</span> </span>
<span id="cb23-87"><a href="#cb23-87" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(<span class="fu">is.na</span>(intnum)<span class="sc">==</span><span class="dv">0</span>)</span>
<span id="cb23-88"><a href="#cb23-88" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-89"><a href="#cb23-89" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-90"><a href="#cb23-90" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-91"><a href="#cb23-91" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-92"><a href="#cb23-92" aria-hidden="true" tabindex="-1"></a><span class="co"># --- Read in the T-2 in 2013 for household heads and wives #2015 family interview number, 2013 earnings</span></span>
<span id="cb23-93"><a href="#cb23-93" aria-hidden="true" tabindex="-1"></a>Dt13 <span class="ot">=</span>   readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/main/labor-market/T2.xlsx"</span>)<span class="sc">%&gt;%</span></span>
<span id="cb23-94"><a href="#cb23-94" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum =</span> ER60002 ,<span class="at">h_earn =</span> ER65021 ,<span class="at">h_ww =</span> ER65005,<span class="at">h_hw =</span> ER65019 , <span class="at">h_earnu=</span> ER65022) <span class="sc">%&gt;%</span></span>
<span id="cb23-95"><a href="#cb23-95" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">w_earn =</span> ER65069 , <span class="at">w_ww =</span> ER65053  , <span class="at">w_hw =</span> ER65067 , <span class="at">w_earnu=</span> ER65070 ) <span class="sc">%&gt;%</span></span>
<span id="cb23-96"><a href="#cb23-96" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">2015</span>) <span class="sc">%&gt;%</span> <span class="fu">select</span>(year, intnum, h_earn,h_ww,h_hw,h_earnu,w_earn,w_ww,w_hw,w_earnu)<span class="sc">%&gt;%</span> </span>
<span id="cb23-97"><a href="#cb23-97" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(<span class="fu">is.na</span>(intnum)<span class="sc">==</span><span class="dv">0</span>)</span>
<span id="cb23-98"><a href="#cb23-98" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-99"><a href="#cb23-99" aria-hidden="true" tabindex="-1"></a><span class="co"># --- Read in the T-2 in 2015 for household heads and wives #2017 family interview number, 2015 earnings</span></span>
<span id="cb23-100"><a href="#cb23-100" aria-hidden="true" tabindex="-1"></a>Dt15 <span class="ot">=</span>   readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/main/labor-market/T2.xlsx"</span>)<span class="sc">%&gt;%</span></span>
<span id="cb23-101"><a href="#cb23-101" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum =</span> ER66002,<span class="at">h_earn =</span> ER71113 ,<span class="at">h_ww =</span> ER71097,<span class="at">h_hw =</span> ER71111, <span class="at">h_earnu=</span> ER71114) <span class="sc">%&gt;%</span></span>
<span id="cb23-102"><a href="#cb23-102" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">w_earn =</span> ER71161, <span class="at">w_ww =</span> ER71145  , <span class="at">w_hw =</span> ER71159 , <span class="at">w_earnu=</span> ER71162) <span class="sc">%&gt;%</span></span>
<span id="cb23-103"><a href="#cb23-103" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">2017</span>) <span class="sc">%&gt;%</span> <span class="fu">select</span>(year, intnum, h_earn,h_ww,h_hw,h_earnu,w_earn,w_ww,w_hw,w_earnu)<span class="sc">%&gt;%</span> </span>
<span id="cb23-104"><a href="#cb23-104" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(<span class="fu">is.na</span>(intnum)<span class="sc">==</span><span class="dv">0</span>)</span>
<span id="cb23-105"><a href="#cb23-105" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-106"><a href="#cb23-106" aria-hidden="true" tabindex="-1"></a><span class="co"># --- Read in the T-2 in 2017 for household heads and wives #2019 family interview number, 2017 earnings</span></span>
<span id="cb23-107"><a href="#cb23-107" aria-hidden="true" tabindex="-1"></a>Dt17 <span class="ot">=</span>   readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/main/labor-market/T2.xlsx"</span>)<span class="sc">%&gt;%</span></span>
<span id="cb23-108"><a href="#cb23-108" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum =</span> ER72002,<span class="at">h_earn =</span> ER77135 ,<span class="at">h_ww =</span> ER77119,<span class="at">h_hw =</span> ER77133, <span class="at">h_earnu=</span> ER77136) <span class="sc">%&gt;%</span></span>
<span id="cb23-109"><a href="#cb23-109" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">w_earn =</span> ER77183 , <span class="at">w_ww =</span> ER77167  , <span class="at">w_hw =</span> ER77181 , <span class="at">w_earnu=</span> ER77184) <span class="sc">%&gt;%</span></span>
<span id="cb23-110"><a href="#cb23-110" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">2019</span>) <span class="sc">%&gt;%</span> <span class="fu">select</span>(year, intnum, h_earn,h_ww,h_hw,h_earnu,w_earn,w_ww,w_hw,w_earnu)<span class="sc">%&gt;%</span> </span>
<span id="cb23-111"><a href="#cb23-111" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(<span class="fu">is.na</span>(intnum)<span class="sc">==</span><span class="dv">0</span>)</span>
<span id="cb23-112"><a href="#cb23-112" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-113"><a href="#cb23-113" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-114"><a href="#cb23-114" aria-hidden="true" tabindex="-1"></a>D01 <span class="ot">&lt;-</span> <span class="fu">select</span>(D01,<span class="fu">c</span>(<span class="st">"MID"</span>,<span class="st">"FID"</span>,<span class="st">"year"</span>,<span class="st">"earn"</span>,<span class="st">"earnu"</span>,<span class="st">"wage"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>))</span>
<span id="cb23-115"><a href="#cb23-115" aria-hidden="true" tabindex="-1"></a>D03 <span class="ot">&lt;-</span> <span class="fu">select</span>(D03,<span class="fu">c</span>(<span class="st">"MID"</span>,<span class="st">"FID"</span>,<span class="st">"year"</span>,<span class="st">"earn"</span>,<span class="st">"earnu"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>))</span>
<span id="cb23-116"><a href="#cb23-116" aria-hidden="true" tabindex="-1"></a>D05 <span class="ot">&lt;-</span> <span class="fu">select</span>(D05,<span class="fu">c</span>(<span class="st">"MID"</span>,<span class="st">"FID"</span>,<span class="st">"year"</span>,<span class="st">"earn"</span>,<span class="st">"earnu"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>))</span>
<span id="cb23-117"><a href="#cb23-117" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-118"><a href="#cb23-118" aria-hidden="true" tabindex="-1"></a>d01 <span class="ot">&lt;-</span> identifiers_panel <span class="sc">%&gt;%</span> </span>
<span id="cb23-119"><a href="#cb23-119" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year<span class="sc">==</span><span class="dv">2003</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb23-120"><a href="#cb23-120" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">MID =</span> intnum68<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> pernum) <span class="sc">%&gt;%</span></span>
<span id="cb23-121"><a href="#cb23-121" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(Dt01) <span class="sc">%&gt;%</span></span>
<span id="cb23-122"><a href="#cb23-122" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">2001</span>)</span>
<span id="cb23-123"><a href="#cb23-123" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-124"><a href="#cb23-124" aria-hidden="true" tabindex="-1"></a>d03 <span class="ot">&lt;-</span> identifiers_panel <span class="sc">%&gt;%</span> </span>
<span id="cb23-125"><a href="#cb23-125" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year<span class="sc">==</span><span class="dv">2005</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb23-126"><a href="#cb23-126" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">MID =</span> intnum68<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> pernum) <span class="sc">%&gt;%</span></span>
<span id="cb23-127"><a href="#cb23-127" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(Dt03) <span class="sc">%&gt;%</span></span>
<span id="cb23-128"><a href="#cb23-128" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">2003</span>)</span>
<span id="cb23-129"><a href="#cb23-129" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-130"><a href="#cb23-130" aria-hidden="true" tabindex="-1"></a>d05 <span class="ot">&lt;-</span> identifiers_panel <span class="sc">%&gt;%</span> </span>
<span id="cb23-131"><a href="#cb23-131" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year<span class="sc">==</span><span class="dv">2007</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb23-132"><a href="#cb23-132" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">MID =</span> intnum68<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> pernum) <span class="sc">%&gt;%</span></span>
<span id="cb23-133"><a href="#cb23-133" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(Dt05) <span class="sc">%&gt;%</span></span>
<span id="cb23-134"><a href="#cb23-134" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">2005</span>)</span>
<span id="cb23-135"><a href="#cb23-135" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-136"><a href="#cb23-136" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-137"><a href="#cb23-137" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-138"><a href="#cb23-138" aria-hidden="true" tabindex="-1"></a>D01 <span class="ot">&lt;-</span> <span class="fu">merge</span>(D01,d01)</span>
<span id="cb23-139"><a href="#cb23-139" aria-hidden="true" tabindex="-1"></a>Ih <span class="ot">=</span> D01<span class="sc">$</span>sn<span class="sc">==</span><span class="dv">1</span></span>
<span id="cb23-140"><a href="#cb23-140" aria-hidden="true" tabindex="-1"></a>D01[Ih,<span class="fu">c</span>(<span class="st">"earn"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>)] <span class="ot">=</span> D01[Ih,<span class="fu">c</span>(<span class="st">"h_earn"</span>,<span class="st">"h_hw"</span>,<span class="st">"h_ww"</span>)]</span>
<span id="cb23-141"><a href="#cb23-141" aria-hidden="true" tabindex="-1"></a>Iw <span class="ot">=</span> D01<span class="sc">$</span>sn<span class="sc">==</span><span class="dv">2</span></span>
<span id="cb23-142"><a href="#cb23-142" aria-hidden="true" tabindex="-1"></a>D01[Iw,<span class="fu">c</span>(<span class="st">"earn"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>)] <span class="ot">=</span> D01[Iw,<span class="fu">c</span>(<span class="st">"w_earn"</span>,<span class="st">"w_hw"</span>,<span class="st">"w_ww"</span>)]</span>
<span id="cb23-143"><a href="#cb23-143" aria-hidden="true" tabindex="-1"></a>D01 <span class="ot">&lt;-</span> <span class="fu">select</span>(D01,<span class="fu">c</span>(<span class="st">"MID"</span>,<span class="st">"FID"</span>,<span class="st">"year"</span>,<span class="st">"earn"</span>,<span class="st">"earnu"</span>,<span class="st">"wage"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>))</span>
<span id="cb23-144"><a href="#cb23-144" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-145"><a href="#cb23-145" aria-hidden="true" tabindex="-1"></a>D03 <span class="ot">&lt;-</span> <span class="fu">merge</span>(D03,d03)</span>
<span id="cb23-146"><a href="#cb23-146" aria-hidden="true" tabindex="-1"></a>Ih <span class="ot">=</span> D03<span class="sc">$</span>sn<span class="sc">==</span><span class="dv">1</span></span>
<span id="cb23-147"><a href="#cb23-147" aria-hidden="true" tabindex="-1"></a>D03[Ih,<span class="fu">c</span>(<span class="st">"earn"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>)] <span class="ot">=</span> D03[Ih,<span class="fu">c</span>(<span class="st">"h_earn"</span>,<span class="st">"h_hw"</span>,<span class="st">"h_ww"</span>)]</span>
<span id="cb23-148"><a href="#cb23-148" aria-hidden="true" tabindex="-1"></a>Iw <span class="ot">=</span> D03<span class="sc">$</span>sn<span class="sc">==</span><span class="dv">2</span></span>
<span id="cb23-149"><a href="#cb23-149" aria-hidden="true" tabindex="-1"></a>D03[Iw,<span class="fu">c</span>(<span class="st">"earn"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>)] <span class="ot">=</span> D03[Iw,<span class="fu">c</span>(<span class="st">"w_earn"</span>,<span class="st">"w_hw"</span>,<span class="st">"w_ww"</span>)]</span>
<span id="cb23-150"><a href="#cb23-150" aria-hidden="true" tabindex="-1"></a>D03 <span class="ot">&lt;-</span> D03<span class="sc">%&gt;%</span> </span>
<span id="cb23-151"><a href="#cb23-151" aria-hidden="true" tabindex="-1"></a><span class="fu">mutate</span>(<span class="at">wage=</span><span class="cn">NA_real_</span>) <span class="co">#hourly wage is not calculated after 2001, will be imputed from earnings and hours</span></span>
<span id="cb23-152"><a href="#cb23-152" aria-hidden="true" tabindex="-1"></a>D03 <span class="ot">&lt;-</span> <span class="fu">select</span>(D03,<span class="fu">c</span>(<span class="st">"MID"</span>,<span class="st">"FID"</span>,<span class="st">"year"</span>,<span class="st">"earn"</span>,<span class="st">"earnu"</span>,<span class="st">"wage"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>))</span>
<span id="cb23-153"><a href="#cb23-153" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-154"><a href="#cb23-154" aria-hidden="true" tabindex="-1"></a>D05 <span class="ot">&lt;-</span> <span class="fu">merge</span>(D05,d05)</span>
<span id="cb23-155"><a href="#cb23-155" aria-hidden="true" tabindex="-1"></a>Ih <span class="ot">=</span> D05<span class="sc">$</span>sn<span class="sc">==</span><span class="dv">1</span></span>
<span id="cb23-156"><a href="#cb23-156" aria-hidden="true" tabindex="-1"></a>D05[Ih,<span class="fu">c</span>(<span class="st">"earn"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>)] <span class="ot">=</span> D05[Ih,<span class="fu">c</span>(<span class="st">"h_earn"</span>,<span class="st">"h_hw"</span>,<span class="st">"h_ww"</span>)]</span>
<span id="cb23-157"><a href="#cb23-157" aria-hidden="true" tabindex="-1"></a>Iw <span class="ot">=</span> D05<span class="sc">$</span>sn<span class="sc">==</span><span class="dv">2</span></span>
<span id="cb23-158"><a href="#cb23-158" aria-hidden="true" tabindex="-1"></a>D05[Iw,<span class="fu">c</span>(<span class="st">"earn"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>)] <span class="ot">=</span> D05[Iw,<span class="fu">c</span>(<span class="st">"w_earn"</span>,<span class="st">"w_hw"</span>,<span class="st">"w_ww"</span>)]</span>
<span id="cb23-159"><a href="#cb23-159" aria-hidden="true" tabindex="-1"></a>D05 <span class="ot">&lt;-</span> D05<span class="sc">%&gt;%</span> </span>
<span id="cb23-160"><a href="#cb23-160" aria-hidden="true" tabindex="-1"></a><span class="fu">mutate</span>(<span class="at">wage=</span><span class="cn">NA_real_</span>) <span class="co">#hourly wage is not calculated after 2001, will be imputed from earnings and hours</span></span>
<span id="cb23-161"><a href="#cb23-161" aria-hidden="true" tabindex="-1"></a>D05 <span class="ot">&lt;-</span> <span class="fu">select</span>(D05,<span class="fu">c</span>(<span class="st">"MID"</span>,<span class="st">"FID"</span>,<span class="st">"year"</span>,<span class="st">"earn"</span>,<span class="st">"earnu"</span>,<span class="st">"wage"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>))</span>
<span id="cb23-162"><a href="#cb23-162" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-163"><a href="#cb23-163" aria-hidden="true" tabindex="-1"></a><span class="co">#labor market outcomes 2 years ago are not reported in the individual file for 2007, so I use family file and generate MID and FID by merging with the identifiers file by family interview number</span></span>
<span id="cb23-164"><a href="#cb23-164" aria-hidden="true" tabindex="-1"></a>D07 <span class="ot">&lt;-</span> identifiers_panel <span class="sc">%&gt;%</span> </span>
<span id="cb23-165"><a href="#cb23-165" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year<span class="sc">==</span><span class="dv">2009</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb23-166"><a href="#cb23-166" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">MID =</span> intnum68<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> pernum,<span class="at">FID=</span>MID) <span class="sc">%&gt;%</span></span>
<span id="cb23-167"><a href="#cb23-167" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(Dt07, <span class="at">by =</span> <span class="fu">c</span>(<span class="st">"intnum"</span>,<span class="st">"year"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb23-168"><a href="#cb23-168" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">2007</span>)</span>
<span id="cb23-169"><a href="#cb23-169" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-170"><a href="#cb23-170" aria-hidden="true" tabindex="-1"></a>D09 <span class="ot">&lt;-</span> identifiers_panel <span class="sc">%&gt;%</span> </span>
<span id="cb23-171"><a href="#cb23-171" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year<span class="sc">==</span><span class="dv">2011</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb23-172"><a href="#cb23-172" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">MID =</span> intnum68<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> pernum,<span class="at">FID=</span>MID) <span class="sc">%&gt;%</span></span>
<span id="cb23-173"><a href="#cb23-173" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(Dt09, <span class="at">by =</span> <span class="fu">c</span>(<span class="st">"intnum"</span>,<span class="st">"year"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb23-174"><a href="#cb23-174" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">2009</span>)</span>
<span id="cb23-175"><a href="#cb23-175" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-176"><a href="#cb23-176" aria-hidden="true" tabindex="-1"></a>D11 <span class="ot">&lt;-</span> identifiers_panel <span class="sc">%&gt;%</span> </span>
<span id="cb23-177"><a href="#cb23-177" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year<span class="sc">==</span><span class="dv">2013</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb23-178"><a href="#cb23-178" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">MID =</span> intnum68<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> pernum,<span class="at">FID=</span>MID) <span class="sc">%&gt;%</span></span>
<span id="cb23-179"><a href="#cb23-179" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(Dt11, <span class="at">by =</span> <span class="fu">c</span>(<span class="st">"intnum"</span>,<span class="st">"year"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb23-180"><a href="#cb23-180" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">2011</span>)</span>
<span id="cb23-181"><a href="#cb23-181" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-182"><a href="#cb23-182" aria-hidden="true" tabindex="-1"></a>D13 <span class="ot">&lt;-</span> identifiers_panel <span class="sc">%&gt;%</span> </span>
<span id="cb23-183"><a href="#cb23-183" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year<span class="sc">==</span><span class="dv">2015</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb23-184"><a href="#cb23-184" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">MID =</span> intnum68<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> pernum,<span class="at">FID=</span>MID) <span class="sc">%&gt;%</span></span>
<span id="cb23-185"><a href="#cb23-185" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(Dt13, <span class="at">by =</span> <span class="fu">c</span>(<span class="st">"intnum"</span>,<span class="st">"year"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb23-186"><a href="#cb23-186" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">2013</span>)</span>
<span id="cb23-187"><a href="#cb23-187" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-188"><a href="#cb23-188" aria-hidden="true" tabindex="-1"></a>D15 <span class="ot">&lt;-</span> identifiers_panel <span class="sc">%&gt;%</span> </span>
<span id="cb23-189"><a href="#cb23-189" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year<span class="sc">==</span><span class="dv">2017</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb23-190"><a href="#cb23-190" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">MID =</span> intnum68<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> pernum,<span class="at">FID=</span>MID) <span class="sc">%&gt;%</span></span>
<span id="cb23-191"><a href="#cb23-191" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(Dt15, <span class="at">by =</span> <span class="fu">c</span>(<span class="st">"intnum"</span>,<span class="st">"year"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb23-192"><a href="#cb23-192" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">2015</span>)</span>
<span id="cb23-193"><a href="#cb23-193" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-194"><a href="#cb23-194" aria-hidden="true" tabindex="-1"></a>D17 <span class="ot">&lt;-</span> identifiers_panel <span class="sc">%&gt;%</span> </span>
<span id="cb23-195"><a href="#cb23-195" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year<span class="sc">==</span><span class="dv">2019</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb23-196"><a href="#cb23-196" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">MID =</span> intnum68<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> pernum,<span class="at">FID=</span>MID) <span class="sc">%&gt;%</span></span>
<span id="cb23-197"><a href="#cb23-197" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(Dt17, <span class="at">by =</span> <span class="fu">c</span>(<span class="st">"intnum"</span>,<span class="st">"year"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb23-198"><a href="#cb23-198" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">2017</span>)</span>
<span id="cb23-199"><a href="#cb23-199" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-200"><a href="#cb23-200" aria-hidden="true" tabindex="-1"></a>Ih <span class="ot">=</span> D07<span class="sc">$</span>sn<span class="sc">==</span><span class="dv">1</span></span>
<span id="cb23-201"><a href="#cb23-201" aria-hidden="true" tabindex="-1"></a>D07[Ih,<span class="fu">c</span>(<span class="st">"earn"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>,<span class="st">"earnu"</span>)] <span class="ot">=</span> D07[Ih,<span class="fu">c</span>(<span class="st">"h_earn"</span>,<span class="st">"h_hw"</span>,<span class="st">"h_ww"</span>,<span class="st">"h_earnu"</span>)]</span>
<span id="cb23-202"><a href="#cb23-202" aria-hidden="true" tabindex="-1"></a>Iw <span class="ot">=</span> D07<span class="sc">$</span>sn<span class="sc">==</span><span class="dv">2</span></span>
<span id="cb23-203"><a href="#cb23-203" aria-hidden="true" tabindex="-1"></a>D07[Iw,<span class="fu">c</span>(<span class="st">"earn"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>,<span class="st">"earnu"</span>)] <span class="ot">=</span> D07[Iw,<span class="fu">c</span>(<span class="st">"w_earn"</span>,<span class="st">"w_hw"</span>,<span class="st">"w_ww"</span>,<span class="st">"w_earnu"</span>)]</span>
<span id="cb23-204"><a href="#cb23-204" aria-hidden="true" tabindex="-1"></a>D07 <span class="ot">&lt;-</span> D07<span class="sc">%&gt;%</span> </span>
<span id="cb23-205"><a href="#cb23-205" aria-hidden="true" tabindex="-1"></a><span class="fu">mutate</span>(<span class="at">wage=</span><span class="cn">NA_real_</span>) <span class="co">#hourly wage is not calculated after 2001, will be imputed from earnings and hours</span></span>
<span id="cb23-206"><a href="#cb23-206" aria-hidden="true" tabindex="-1"></a>D07 <span class="ot">&lt;-</span> <span class="fu">select</span>(D07,<span class="fu">c</span>(<span class="st">"MID"</span>,<span class="st">"FID"</span>,<span class="st">"year"</span>,<span class="st">"earn"</span>,<span class="st">"earnu"</span>,<span class="st">"wage"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>))</span>
<span id="cb23-207"><a href="#cb23-207" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-208"><a href="#cb23-208" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-209"><a href="#cb23-209" aria-hidden="true" tabindex="-1"></a>Ih <span class="ot">=</span> D09<span class="sc">$</span>sn<span class="sc">==</span><span class="dv">1</span></span>
<span id="cb23-210"><a href="#cb23-210" aria-hidden="true" tabindex="-1"></a>D09[Ih,<span class="fu">c</span>(<span class="st">"earn"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>,<span class="st">"earnu"</span>)] <span class="ot">=</span> D09[Ih,<span class="fu">c</span>(<span class="st">"h_earn"</span>,<span class="st">"h_hw"</span>,<span class="st">"h_ww"</span>,<span class="st">"h_earnu"</span>)]</span>
<span id="cb23-211"><a href="#cb23-211" aria-hidden="true" tabindex="-1"></a>Iw <span class="ot">=</span> D09<span class="sc">$</span>sn<span class="sc">==</span><span class="dv">2</span></span>
<span id="cb23-212"><a href="#cb23-212" aria-hidden="true" tabindex="-1"></a>D09[Iw,<span class="fu">c</span>(<span class="st">"earn"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>,<span class="st">"earnu"</span>)] <span class="ot">=</span> D09[Iw,<span class="fu">c</span>(<span class="st">"w_earn"</span>,<span class="st">"w_hw"</span>,<span class="st">"w_ww"</span>,<span class="st">"w_earnu"</span>)]</span>
<span id="cb23-213"><a href="#cb23-213" aria-hidden="true" tabindex="-1"></a>D09 <span class="ot">&lt;-</span> D09<span class="sc">%&gt;%</span> </span>
<span id="cb23-214"><a href="#cb23-214" aria-hidden="true" tabindex="-1"></a><span class="fu">mutate</span>(<span class="at">wage=</span><span class="cn">NA_real_</span>) <span class="co">#hourly wage is not calculated after 2001, will be imputed from earnings and hours</span></span>
<span id="cb23-215"><a href="#cb23-215" aria-hidden="true" tabindex="-1"></a>D09 <span class="ot">&lt;-</span> <span class="fu">select</span>(D09,<span class="fu">c</span>(<span class="st">"MID"</span>,<span class="st">"FID"</span>,<span class="st">"year"</span>,<span class="st">"earn"</span>,<span class="st">"earnu"</span>,<span class="st">"wage"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>))</span>
<span id="cb23-216"><a href="#cb23-216" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-217"><a href="#cb23-217" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-218"><a href="#cb23-218" aria-hidden="true" tabindex="-1"></a>Ih <span class="ot">=</span> D11<span class="sc">$</span>sn<span class="sc">==</span><span class="dv">1</span></span>
<span id="cb23-219"><a href="#cb23-219" aria-hidden="true" tabindex="-1"></a>D11[Ih,<span class="fu">c</span>(<span class="st">"earn"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>,<span class="st">"earnu"</span>)] <span class="ot">=</span> D11[Ih,<span class="fu">c</span>(<span class="st">"h_earn"</span>,<span class="st">"h_hw"</span>,<span class="st">"h_ww"</span>,<span class="st">"h_earnu"</span>)]</span>
<span id="cb23-220"><a href="#cb23-220" aria-hidden="true" tabindex="-1"></a>Iw <span class="ot">=</span> D11<span class="sc">$</span>sn<span class="sc">==</span><span class="dv">2</span></span>
<span id="cb23-221"><a href="#cb23-221" aria-hidden="true" tabindex="-1"></a>D11[Iw,<span class="fu">c</span>(<span class="st">"earn"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>,<span class="st">"earnu"</span>)] <span class="ot">=</span> D11[Iw,<span class="fu">c</span>(<span class="st">"w_earn"</span>,<span class="st">"w_hw"</span>,<span class="st">"w_ww"</span>,<span class="st">"w_earnu"</span>)]</span>
<span id="cb23-222"><a href="#cb23-222" aria-hidden="true" tabindex="-1"></a>D11 <span class="ot">&lt;-</span> D11<span class="sc">%&gt;%</span> </span>
<span id="cb23-223"><a href="#cb23-223" aria-hidden="true" tabindex="-1"></a><span class="fu">mutate</span>(<span class="at">wage=</span><span class="cn">NA_real_</span>) <span class="co">#hourly wage is not calculated after 2001, will be imputed from earnings and hours</span></span>
<span id="cb23-224"><a href="#cb23-224" aria-hidden="true" tabindex="-1"></a>D11 <span class="ot">&lt;-</span> <span class="fu">select</span>(D11,<span class="fu">c</span>(<span class="st">"MID"</span>,<span class="st">"FID"</span>,<span class="st">"year"</span>,<span class="st">"earn"</span>,<span class="st">"earnu"</span>,<span class="st">"wage"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>))</span>
<span id="cb23-225"><a href="#cb23-225" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-226"><a href="#cb23-226" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-227"><a href="#cb23-227" aria-hidden="true" tabindex="-1"></a>Ih <span class="ot">=</span> D13<span class="sc">$</span>sn<span class="sc">==</span><span class="dv">1</span></span>
<span id="cb23-228"><a href="#cb23-228" aria-hidden="true" tabindex="-1"></a>D13[Ih,<span class="fu">c</span>(<span class="st">"earn"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>,<span class="st">"earnu"</span>)] <span class="ot">=</span> D13[Ih,<span class="fu">c</span>(<span class="st">"h_earn"</span>,<span class="st">"h_hw"</span>,<span class="st">"h_ww"</span>,<span class="st">"h_earnu"</span>)]</span>
<span id="cb23-229"><a href="#cb23-229" aria-hidden="true" tabindex="-1"></a>Iw <span class="ot">=</span> D13<span class="sc">$</span>sn<span class="sc">==</span><span class="dv">2</span></span>
<span id="cb23-230"><a href="#cb23-230" aria-hidden="true" tabindex="-1"></a>D13[Iw,<span class="fu">c</span>(<span class="st">"earn"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>,<span class="st">"earnu"</span>)] <span class="ot">=</span> D13[Iw,<span class="fu">c</span>(<span class="st">"w_earn"</span>,<span class="st">"w_hw"</span>,<span class="st">"w_ww"</span>,<span class="st">"w_earnu"</span>)]</span>
<span id="cb23-231"><a href="#cb23-231" aria-hidden="true" tabindex="-1"></a>D13 <span class="ot">&lt;-</span> D13<span class="sc">%&gt;%</span> </span>
<span id="cb23-232"><a href="#cb23-232" aria-hidden="true" tabindex="-1"></a><span class="fu">mutate</span>(<span class="at">wage=</span><span class="cn">NA_real_</span>) <span class="co">#hourly wage is not calculated after 2001, will be imputed from earnings and hours</span></span>
<span id="cb23-233"><a href="#cb23-233" aria-hidden="true" tabindex="-1"></a>D13 <span class="ot">&lt;-</span> <span class="fu">select</span>(D13,<span class="fu">c</span>(<span class="st">"MID"</span>,<span class="st">"FID"</span>,<span class="st">"year"</span>,<span class="st">"earn"</span>,<span class="st">"earnu"</span>,<span class="st">"wage"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>))</span>
<span id="cb23-234"><a href="#cb23-234" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-235"><a href="#cb23-235" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-236"><a href="#cb23-236" aria-hidden="true" tabindex="-1"></a>Ih <span class="ot">=</span> D15<span class="sc">$</span>sn<span class="sc">==</span><span class="dv">1</span></span>
<span id="cb23-237"><a href="#cb23-237" aria-hidden="true" tabindex="-1"></a>D15[Ih,<span class="fu">c</span>(<span class="st">"earn"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>,<span class="st">"earnu"</span>)] <span class="ot">=</span> D15[Ih,<span class="fu">c</span>(<span class="st">"h_earn"</span>,<span class="st">"h_hw"</span>,<span class="st">"h_ww"</span>,<span class="st">"h_earnu"</span>)]</span>
<span id="cb23-238"><a href="#cb23-238" aria-hidden="true" tabindex="-1"></a>Iw <span class="ot">=</span> D15<span class="sc">$</span>sn<span class="sc">==</span><span class="dv">2</span></span>
<span id="cb23-239"><a href="#cb23-239" aria-hidden="true" tabindex="-1"></a>D15[Iw,<span class="fu">c</span>(<span class="st">"earn"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>,<span class="st">"earnu"</span>)] <span class="ot">=</span> D15[Iw,<span class="fu">c</span>(<span class="st">"w_earn"</span>,<span class="st">"w_hw"</span>,<span class="st">"w_ww"</span>,<span class="st">"w_earnu"</span>)]</span>
<span id="cb23-240"><a href="#cb23-240" aria-hidden="true" tabindex="-1"></a>D15 <span class="ot">&lt;-</span> D15<span class="sc">%&gt;%</span> </span>
<span id="cb23-241"><a href="#cb23-241" aria-hidden="true" tabindex="-1"></a><span class="fu">mutate</span>(<span class="at">wage=</span><span class="cn">NA_real_</span>) <span class="co">#hourly wage is not calculated after 2001, will be imputed from earnings and hours</span></span>
<span id="cb23-242"><a href="#cb23-242" aria-hidden="true" tabindex="-1"></a>D15 <span class="ot">&lt;-</span> <span class="fu">select</span>(D15,<span class="fu">c</span>(<span class="st">"MID"</span>,<span class="st">"FID"</span>,<span class="st">"year"</span>,<span class="st">"earn"</span>,<span class="st">"earnu"</span>,<span class="st">"wage"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>))</span>
<span id="cb23-243"><a href="#cb23-243" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-244"><a href="#cb23-244" aria-hidden="true" tabindex="-1"></a>Ih <span class="ot">=</span> D17<span class="sc">$</span>sn<span class="sc">==</span><span class="dv">1</span></span>
<span id="cb23-245"><a href="#cb23-245" aria-hidden="true" tabindex="-1"></a>D17[Ih,<span class="fu">c</span>(<span class="st">"earn"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>,<span class="st">"earnu"</span>)] <span class="ot">=</span> D17[Ih,<span class="fu">c</span>(<span class="st">"h_earn"</span>,<span class="st">"h_hw"</span>,<span class="st">"h_ww"</span>,<span class="st">"h_earnu"</span>)]</span>
<span id="cb23-246"><a href="#cb23-246" aria-hidden="true" tabindex="-1"></a>Iw <span class="ot">=</span> D17<span class="sc">$</span>sn<span class="sc">==</span><span class="dv">2</span></span>
<span id="cb23-247"><a href="#cb23-247" aria-hidden="true" tabindex="-1"></a>D17[Iw,<span class="fu">c</span>(<span class="st">"earn"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>,<span class="st">"earnu"</span>)] <span class="ot">=</span> D17[Iw,<span class="fu">c</span>(<span class="st">"w_earn"</span>,<span class="st">"w_hw"</span>,<span class="st">"w_ww"</span>,<span class="st">"w_earnu"</span>)]</span>
<span id="cb23-248"><a href="#cb23-248" aria-hidden="true" tabindex="-1"></a>D17 <span class="ot">&lt;-</span> D17<span class="sc">%&gt;%</span> </span>
<span id="cb23-249"><a href="#cb23-249" aria-hidden="true" tabindex="-1"></a><span class="fu">mutate</span>(<span class="at">wage=</span><span class="cn">NA_real_</span>) <span class="co">#hourly wage is not calculated after 2001, will be imputed from earnings and hours</span></span>
<span id="cb23-250"><a href="#cb23-250" aria-hidden="true" tabindex="-1"></a>D17 <span class="ot">&lt;-</span> <span class="fu">select</span>(D17,<span class="fu">c</span>(<span class="st">"MID"</span>,<span class="st">"FID"</span>,<span class="st">"year"</span>,<span class="st">"earn"</span>,<span class="st">"earnu"</span>,<span class="st">"wage"</span>,<span class="st">"hw"</span>,<span class="st">"ww"</span>))</span>
<span id="cb23-251"><a href="#cb23-251" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-252"><a href="#cb23-252" aria-hidden="true" tabindex="-1"></a>earnings_panel_supplement <span class="ot">&lt;-</span> <span class="fu">rbind</span>(D97,D99,D01,D03,D05,D07,D09,D11,D13,D15,D17) <span class="sc">%&gt;%</span></span>
<span id="cb23-253"><a href="#cb23-253" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">earn =</span> <span class="fu">na_if</span>(<span class="fu">na_if</span>(<span class="fu">na_if</span>(<span class="fu">na_if</span>(earn,<span class="sc">-</span><span class="dv">9999999</span>),<span class="sc">-</span><span class="dv">999999</span>),<span class="dv">99999999</span>),<span class="dv">9999999</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb23-254"><a href="#cb23-254" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">earn =</span> <span class="fu">na_if</span>(<span class="fu">na_if</span>(<span class="fu">na_if</span>(earn,<span class="sc">-</span><span class="dv">999998</span>),<span class="dv">9999998</span>),<span class="dv">99999998</span>))<span class="sc">%&gt;%</span></span>
<span id="cb23-255"><a href="#cb23-255" aria-hidden="true" tabindex="-1"></a>  <span class="co">#mutate(earn = case_when(earnu==1 ~ earn*hw*ww,earnu==2 ~ earn*365,earnu==3 ~ earn*ww, earnu==4 ~ earn*ww/2,earnu==5 ~ earn*12, earnu==6 ~ earn, TRUE ~ NA_real_)) %&gt;%</span></span>
<span id="cb23-256"><a href="#cb23-256" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">ww =</span> <span class="fu">na_if</span>(<span class="fu">na_if</span>(ww,<span class="dv">99</span>),<span class="dv">98</span>),<span class="at">hw=</span><span class="fu">na_if</span>(<span class="fu">na_if</span>(hw,<span class="dv">999</span>),<span class="dv">998</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb23-257"><a href="#cb23-257" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">hrs =</span> ww<span class="sc">*</span>hw) <span class="sc">%&gt;%</span></span>
<span id="cb23-258"><a href="#cb23-258" aria-hidden="true" tabindex="-1"></a>  <span class="co">#mutate(wage2 = case_when(earn&gt;0 &amp; hrs&gt;0 ~ earn/hrs,TRUE ~ NA_real_),0) %&gt;%</span></span>
<span id="cb23-259"><a href="#cb23-259" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">wage =</span> <span class="fu">case_when</span>(wage<span class="sc">&lt;=</span><span class="dv">0</span> <span class="sc">~</span> <span class="cn">NA_real_</span>,wage<span class="sc">==</span><span class="dv">999</span> <span class="sc">~</span> <span class="cn">NA_real_</span>,<span class="cn">TRUE</span> <span class="sc">~</span> wage)) <span class="sc">%&gt;%</span></span>
<span id="cb23-260"><a href="#cb23-260" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">wage =</span> <span class="fu">case_when</span>(earn<span class="sc">&gt;</span><span class="dv">0</span> <span class="sc">&amp;</span> earnu<span class="sc">==</span><span class="dv">6</span> <span class="sc">&amp;</span> hrs<span class="sc">&gt;</span><span class="dv">0</span> <span class="sc">&amp;</span> <span class="fu">is.na</span>(wage) <span class="sc">~</span> earn<span class="sc">/</span>hrs, <span class="cn">TRUE</span> <span class="sc">~</span> wage))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="main-interview-total-income" class="level2">
<h2 class="anchored" data-anchor-id="main-interview-total-income">Main Interview: Total Income</h2>
<div class="cell">
<div class="sourceCode cell-code" id="cb24"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a>Income_ly <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/main/total_income/total_income.xlsx"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb24-2"><a href="#cb24-2" aria-hidden="true" tabindex="-1"></a><span class="fu">rename</span>(<span class="at">intnum97=</span>ER10002, <span class="at">tax_income97=</span>ER12069, <span class="at">total_income97=</span>ER12079) <span class="sc">%&gt;%</span></span>
<span id="cb24-3"><a href="#cb24-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum99=</span>ER13002, <span class="at">tax_income99=</span>ER16452, <span class="at">total_income99=</span>ER16462) <span class="sc">%&gt;%</span></span>
<span id="cb24-4"><a href="#cb24-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum01=</span>ER17002, <span class="at">tax_income01=</span>ER20449, <span class="at">total_income01=</span>ER20456) <span class="sc">%&gt;%</span></span>
<span id="cb24-5"><a href="#cb24-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum03=</span>ER21002, <span class="at">tax_income03=</span>ER24100, <span class="at">total_income03=</span>ER24099) <span class="sc">%&gt;%</span></span>
<span id="cb24-6"><a href="#cb24-6" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum05=</span>ER25002, <span class="at">tax_income05=</span>ER27953, <span class="at">total_income05=</span>ER28037) <span class="sc">%&gt;%</span></span>
<span id="cb24-7"><a href="#cb24-7" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum07=</span>ER36002, <span class="at">tax_income07=</span>ER40943, <span class="at">total_income07=</span>ER41027)</span>
<span id="cb24-8"><a href="#cb24-8" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb24-9"><a href="#cb24-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-10"><a href="#cb24-10" aria-hidden="true" tabindex="-1"></a>Income_T2 <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/main/total_income/total_income.xlsx"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb24-11"><a href="#cb24-11" aria-hidden="true" tabindex="-1"></a><span class="fu">rename</span>(<span class="at">intnum99=</span>ER13002, <span class="at">total_income97=</span>ER16219) <span class="sc">%&gt;%</span></span>
<span id="cb24-12"><a href="#cb24-12" aria-hidden="true" tabindex="-1"></a><span class="fu">rename</span>(<span class="at">intnum01=</span>ER17002, <span class="at">total_income99=</span>ER20165) <span class="sc">%&gt;%</span></span>
<span id="cb24-13"><a href="#cb24-13" aria-hidden="true" tabindex="-1"></a><span class="fu">rename</span>(<span class="at">intnum03=</span>ER21002, <span class="at">total_income01=</span>ER23764)</span>
<span id="cb24-14"><a href="#cb24-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-15"><a href="#cb24-15" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-16"><a href="#cb24-16" aria-hidden="true" tabindex="-1"></a><span class="co"># Separate files by year</span></span>
<span id="cb24-17"><a href="#cb24-17" aria-hidden="true" tabindex="-1"></a>I97 <span class="ot">&lt;-</span> Income_ly <span class="sc">%&gt;%</span> <span class="fu">select</span>(intnum97,tax_income97,total_income97) <span class="sc">%&gt;%</span></span>
<span id="cb24-18"><a href="#cb24-18" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum=</span>intnum97,<span class="at">tax_income=</span>tax_income97,<span class="at">total_income=</span>total_income97) <span class="sc">%&gt;%</span></span>
<span id="cb24-19"><a href="#cb24-19" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year=</span><span class="dv">1997</span>)</span>
<span id="cb24-20"><a href="#cb24-20" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-21"><a href="#cb24-21" aria-hidden="true" tabindex="-1"></a>I99 <span class="ot">&lt;-</span> Income_ly <span class="sc">%&gt;%</span> <span class="fu">select</span>(intnum99,tax_income99,total_income99) <span class="sc">%&gt;%</span></span>
<span id="cb24-22"><a href="#cb24-22" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum=</span>intnum99,<span class="at">tax_income=</span>tax_income99,<span class="at">total_income=</span>total_income99) <span class="sc">%&gt;%</span></span>
<span id="cb24-23"><a href="#cb24-23" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year=</span><span class="dv">1999</span>)</span>
<span id="cb24-24"><a href="#cb24-24" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-25"><a href="#cb24-25" aria-hidden="true" tabindex="-1"></a>I99_T2 <span class="ot">&lt;-</span> Income_T2 <span class="sc">%&gt;%</span> <span class="fu">select</span>(intnum99,total_income97) <span class="sc">%&gt;%</span></span>
<span id="cb24-26"><a href="#cb24-26" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum=</span>intnum99,<span class="at">total_income=</span>total_income97) <span class="sc">%&gt;%</span></span>
<span id="cb24-27"><a href="#cb24-27" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year=</span><span class="dv">1999</span>, <span class="at">tax_income=</span><span class="cn">NA_real_</span>)</span>
<span id="cb24-28"><a href="#cb24-28" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-29"><a href="#cb24-29" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-30"><a href="#cb24-30" aria-hidden="true" tabindex="-1"></a>I01 <span class="ot">&lt;-</span> Income_ly <span class="sc">%&gt;%</span> <span class="fu">select</span>(intnum01,tax_income01,total_income01) <span class="sc">%&gt;%</span></span>
<span id="cb24-31"><a href="#cb24-31" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum=</span>intnum01,<span class="at">tax_income=</span>tax_income01,<span class="at">total_income=</span>total_income01) <span class="sc">%&gt;%</span></span>
<span id="cb24-32"><a href="#cb24-32" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year=</span><span class="dv">2001</span>)</span>
<span id="cb24-33"><a href="#cb24-33" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-34"><a href="#cb24-34" aria-hidden="true" tabindex="-1"></a>I01_T2 <span class="ot">&lt;-</span> Income_T2 <span class="sc">%&gt;%</span> <span class="fu">select</span>(intnum01,total_income99) <span class="sc">%&gt;%</span></span>
<span id="cb24-35"><a href="#cb24-35" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum=</span>intnum01,<span class="at">total_income=</span>total_income99) <span class="sc">%&gt;%</span></span>
<span id="cb24-36"><a href="#cb24-36" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year=</span><span class="dv">2001</span>, <span class="at">tax_income=</span><span class="cn">NA_real_</span>)</span>
<span id="cb24-37"><a href="#cb24-37" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-38"><a href="#cb24-38" aria-hidden="true" tabindex="-1"></a>I03 <span class="ot">&lt;-</span> Income_ly <span class="sc">%&gt;%</span> <span class="fu">select</span>(intnum03,tax_income03,total_income03) <span class="sc">%&gt;%</span></span>
<span id="cb24-39"><a href="#cb24-39" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum=</span>intnum03,<span class="at">tax_income=</span>tax_income03,<span class="at">total_income=</span>total_income03) <span class="sc">%&gt;%</span></span>
<span id="cb24-40"><a href="#cb24-40" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year=</span><span class="dv">2003</span>)</span>
<span id="cb24-41"><a href="#cb24-41" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-42"><a href="#cb24-42" aria-hidden="true" tabindex="-1"></a>I03_T2 <span class="ot">&lt;-</span> Income_T2 <span class="sc">%&gt;%</span> <span class="fu">select</span>(intnum03,total_income01) <span class="sc">%&gt;%</span></span>
<span id="cb24-43"><a href="#cb24-43" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum=</span>intnum03,<span class="at">total_income=</span>total_income01) <span class="sc">%&gt;%</span></span>
<span id="cb24-44"><a href="#cb24-44" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year=</span><span class="dv">2003</span>, <span class="at">tax_income=</span><span class="cn">NA_real_</span>)</span>
<span id="cb24-45"><a href="#cb24-45" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-46"><a href="#cb24-46" aria-hidden="true" tabindex="-1"></a>I05 <span class="ot">&lt;-</span> Income_ly <span class="sc">%&gt;%</span> <span class="fu">select</span>(intnum05,tax_income05,total_income05) <span class="sc">%&gt;%</span></span>
<span id="cb24-47"><a href="#cb24-47" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum=</span>intnum05,<span class="at">tax_income=</span>tax_income05,<span class="at">total_income=</span>total_income05) <span class="sc">%&gt;%</span></span>
<span id="cb24-48"><a href="#cb24-48" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year=</span><span class="dv">2005</span>)</span>
<span id="cb24-49"><a href="#cb24-49" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-50"><a href="#cb24-50" aria-hidden="true" tabindex="-1"></a>I07 <span class="ot">&lt;-</span> Income_ly <span class="sc">%&gt;%</span> <span class="fu">select</span>(intnum07,tax_income07,total_income07) <span class="sc">%&gt;%</span></span>
<span id="cb24-51"><a href="#cb24-51" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum=</span>intnum07,<span class="at">tax_income=</span>tax_income07,<span class="at">total_income=</span>total_income07) <span class="sc">%&gt;%</span></span>
<span id="cb24-52"><a href="#cb24-52" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year=</span><span class="dv">2007</span>)</span>
<span id="cb24-53"><a href="#cb24-53" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-54"><a href="#cb24-54" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-55"><a href="#cb24-55" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-56"><a href="#cb24-56" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-57"><a href="#cb24-57" aria-hidden="true" tabindex="-1"></a>i97 <span class="ot">&lt;-</span> identifiers_panel <span class="sc">%&gt;%</span> </span>
<span id="cb24-58"><a href="#cb24-58" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year<span class="sc">==</span><span class="dv">1997</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb24-59"><a href="#cb24-59" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">X =</span> <span class="cn">NULL</span>,<span class="at">MID =</span> intnum68<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> pernum) <span class="sc">%&gt;%</span></span>
<span id="cb24-60"><a href="#cb24-60" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(MID, year, intnum)<span class="sc">%&gt;%</span></span>
<span id="cb24-61"><a href="#cb24-61" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(I97) <span class="sc">%&gt;%</span></span>
<span id="cb24-62"><a href="#cb24-62" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">1996</span>)</span>
<span id="cb24-63"><a href="#cb24-63" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-64"><a href="#cb24-64" aria-hidden="true" tabindex="-1"></a>i99 <span class="ot">&lt;-</span> identifiers_panel <span class="sc">%&gt;%</span> </span>
<span id="cb24-65"><a href="#cb24-65" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year<span class="sc">==</span><span class="dv">1999</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb24-66"><a href="#cb24-66" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">X =</span> <span class="cn">NULL</span>,<span class="at">MID =</span> intnum68<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> pernum) <span class="sc">%&gt;%</span></span>
<span id="cb24-67"><a href="#cb24-67" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(MID, year, intnum)<span class="sc">%&gt;%</span></span>
<span id="cb24-68"><a href="#cb24-68" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(I99) <span class="sc">%&gt;%</span></span>
<span id="cb24-69"><a href="#cb24-69" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">1998</span>)</span>
<span id="cb24-70"><a href="#cb24-70" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-71"><a href="#cb24-71" aria-hidden="true" tabindex="-1"></a>i99_T2 <span class="ot">&lt;-</span> identifiers_panel <span class="sc">%&gt;%</span> </span>
<span id="cb24-72"><a href="#cb24-72" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year<span class="sc">==</span><span class="dv">1999</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb24-73"><a href="#cb24-73" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">X =</span> <span class="cn">NULL</span>,<span class="at">MID =</span> intnum68<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> pernum) <span class="sc">%&gt;%</span></span>
<span id="cb24-74"><a href="#cb24-74" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(MID, year, intnum)<span class="sc">%&gt;%</span></span>
<span id="cb24-75"><a href="#cb24-75" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(I99_T2) <span class="sc">%&gt;%</span></span>
<span id="cb24-76"><a href="#cb24-76" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">total_income=</span><span class="fu">na_if</span>(<span class="fu">na_if</span>(total_income,<span class="dv">9999999</span>),<span class="dv">9999998</span>))<span class="sc">%&gt;%</span></span>
<span id="cb24-77"><a href="#cb24-77" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">1997</span>)</span>
<span id="cb24-78"><a href="#cb24-78" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-79"><a href="#cb24-79" aria-hidden="true" tabindex="-1"></a>i01 <span class="ot">&lt;-</span> identifiers_panel <span class="sc">%&gt;%</span> </span>
<span id="cb24-80"><a href="#cb24-80" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year<span class="sc">==</span><span class="dv">2001</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb24-81"><a href="#cb24-81" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">X =</span> <span class="cn">NULL</span>,<span class="at">MID =</span> intnum68<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> pernum) <span class="sc">%&gt;%</span></span>
<span id="cb24-82"><a href="#cb24-82" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(MID, year, intnum)<span class="sc">%&gt;%</span></span>
<span id="cb24-83"><a href="#cb24-83" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(I01) <span class="sc">%&gt;%</span></span>
<span id="cb24-84"><a href="#cb24-84" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">2000</span>)</span>
<span id="cb24-85"><a href="#cb24-85" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-86"><a href="#cb24-86" aria-hidden="true" tabindex="-1"></a>i01_T2 <span class="ot">&lt;-</span> identifiers_panel <span class="sc">%&gt;%</span> </span>
<span id="cb24-87"><a href="#cb24-87" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year<span class="sc">==</span><span class="dv">2001</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb24-88"><a href="#cb24-88" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">X =</span> <span class="cn">NULL</span>,<span class="at">MID =</span> intnum68<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> pernum) <span class="sc">%&gt;%</span></span>
<span id="cb24-89"><a href="#cb24-89" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(MID, year, intnum)<span class="sc">%&gt;%</span></span>
<span id="cb24-90"><a href="#cb24-90" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(I01_T2) <span class="sc">%&gt;%</span></span>
<span id="cb24-91"><a href="#cb24-91" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">total_income=</span><span class="fu">na_if</span>(<span class="fu">na_if</span>(total_income,<span class="dv">999999999</span>),<span class="dv">999999998</span>))<span class="sc">%&gt;%</span></span>
<span id="cb24-92"><a href="#cb24-92" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">1999</span>)</span>
<span id="cb24-93"><a href="#cb24-93" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-94"><a href="#cb24-94" aria-hidden="true" tabindex="-1"></a>i03 <span class="ot">&lt;-</span> identifiers_panel <span class="sc">%&gt;%</span> </span>
<span id="cb24-95"><a href="#cb24-95" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year<span class="sc">==</span><span class="dv">2003</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb24-96"><a href="#cb24-96" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">X =</span> <span class="cn">NULL</span>,<span class="at">MID =</span> intnum68<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> pernum) <span class="sc">%&gt;%</span></span>
<span id="cb24-97"><a href="#cb24-97" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(MID, year, intnum)<span class="sc">%&gt;%</span></span>
<span id="cb24-98"><a href="#cb24-98" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(I03) <span class="sc">%&gt;%</span></span>
<span id="cb24-99"><a href="#cb24-99" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">2002</span>)</span>
<span id="cb24-100"><a href="#cb24-100" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-101"><a href="#cb24-101" aria-hidden="true" tabindex="-1"></a>i03_T2 <span class="ot">&lt;-</span> identifiers_panel <span class="sc">%&gt;%</span> </span>
<span id="cb24-102"><a href="#cb24-102" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year<span class="sc">==</span><span class="dv">2003</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb24-103"><a href="#cb24-103" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">X =</span> <span class="cn">NULL</span>,<span class="at">MID =</span> intnum68<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> pernum) <span class="sc">%&gt;%</span></span>
<span id="cb24-104"><a href="#cb24-104" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(MID, year, intnum)<span class="sc">%&gt;%</span></span>
<span id="cb24-105"><a href="#cb24-105" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(I03_T2) <span class="sc">%&gt;%</span></span>
<span id="cb24-106"><a href="#cb24-106" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">total_income=</span><span class="fu">na_if</span>(<span class="fu">na_if</span>(total_income,<span class="dv">999999999</span>),<span class="dv">999999998</span>))<span class="sc">%&gt;%</span></span>
<span id="cb24-107"><a href="#cb24-107" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">2001</span>)</span>
<span id="cb24-108"><a href="#cb24-108" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-109"><a href="#cb24-109" aria-hidden="true" tabindex="-1"></a>i05 <span class="ot">&lt;-</span> identifiers_panel <span class="sc">%&gt;%</span> </span>
<span id="cb24-110"><a href="#cb24-110" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year<span class="sc">==</span><span class="dv">2005</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb24-111"><a href="#cb24-111" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">X =</span> <span class="cn">NULL</span>,<span class="at">MID =</span> intnum68<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> pernum) <span class="sc">%&gt;%</span></span>
<span id="cb24-112"><a href="#cb24-112" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(MID, year, intnum)<span class="sc">%&gt;%</span></span>
<span id="cb24-113"><a href="#cb24-113" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(I05) <span class="sc">%&gt;%</span></span>
<span id="cb24-114"><a href="#cb24-114" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">2004</span>)</span>
<span id="cb24-115"><a href="#cb24-115" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-116"><a href="#cb24-116" aria-hidden="true" tabindex="-1"></a>i07 <span class="ot">&lt;-</span> identifiers_panel <span class="sc">%&gt;%</span> </span>
<span id="cb24-117"><a href="#cb24-117" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year<span class="sc">==</span><span class="dv">2007</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb24-118"><a href="#cb24-118" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">X =</span> <span class="cn">NULL</span>,<span class="at">MID =</span> intnum68<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> pernum) <span class="sc">%&gt;%</span></span>
<span id="cb24-119"><a href="#cb24-119" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(MID, year, intnum)<span class="sc">%&gt;%</span></span>
<span id="cb24-120"><a href="#cb24-120" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(I07) <span class="sc">%&gt;%</span></span>
<span id="cb24-121"><a href="#cb24-121" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">2006</span>)</span>
<span id="cb24-122"><a href="#cb24-122" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-123"><a href="#cb24-123" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-124"><a href="#cb24-124" aria-hidden="true" tabindex="-1"></a>total_income <span class="ot">&lt;-</span> <span class="fu">rbind</span>(i97,i99,i99_T2,i01,i01_T2,i03,i03_T2,i05,i07) <span class="sc">%&gt;%</span></span>
<span id="cb24-125"><a href="#cb24-125" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(<span class="sc">-</span>intnum)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
</section>
<section id="arranging-psid-cds-data" class="level1">
<h1>Arranging PSID-CDS Data</h1>
<section id="assessments" class="level2">
<h2 class="anchored" data-anchor-id="assessments">Assessments</h2>
<p>Arrange the child assessments into a panel.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb25"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a>D <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/cds/assessments/ChildAssessments.xlsx"</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">KID =</span> ER30001<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> ER30002)</span>
<span id="cb25-3"><a href="#cb25-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-4"><a href="#cb25-4" aria-hidden="true" tabindex="-1"></a><span class="co"># first we want to arrange the data nicely. We have the same scores for each year. They are:</span></span>
<span id="cb25-5"><a href="#cb25-5" aria-hidden="true" tabindex="-1"></a>col_names <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"LW_std"</span>,<span class="st">"LW_raw"</span>,<span class="st">"PC_std"</span>,<span class="st">"PC_raw"</span>,<span class="st">"AP_std"</span>,<span class="st">"AP_raw"</span>,<span class="st">"DigSpan"</span>,<span class="st">"BPE"</span>,<span class="st">"BPN"</span>)</span>
<span id="cb25-6"><a href="#cb25-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-7"><a href="#cb25-7" aria-hidden="true" tabindex="-1"></a><span class="co"># 3 vectors with the corresponding variable names for each year</span></span>
<span id="cb25-8"><a href="#cb25-8" aria-hidden="true" tabindex="-1"></a>names97 <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"Q3LW_SS"</span>,<span class="st">"Q3LWRAW"</span>,<span class="st">"Q3PC_SS"</span>,<span class="st">"Q3PCRAW"</span>,<span class="st">"Q3AP_SS"</span>,<span class="st">"Q3APRAW"</span>,<span class="st">"Q3DSTOT"</span>,<span class="st">"BPI_E97"</span>,<span class="st">"BPI_N97"</span>)</span>
<span id="cb25-9"><a href="#cb25-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-10"><a href="#cb25-10" aria-hidden="true" tabindex="-1"></a>names02 <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"Q24LWSS"</span>,<span class="st">"Q24LWRAW"</span>,<span class="st">"Q24PCSS"</span>,<span class="st">"Q24PCRAW"</span>,<span class="st">"Q24APSS"</span>,<span class="st">"Q24APRAW"</span>,<span class="st">"Q24DSTO"</span>,<span class="st">"BPI_E02"</span>,<span class="st">"BPI_N02"</span>)</span>
<span id="cb25-11"><a href="#cb25-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-12"><a href="#cb25-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-13"><a href="#cb25-13" aria-hidden="true" tabindex="-1"></a>names07 <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"Q34LWSS"</span>,<span class="st">"Q34LWRAW"</span>,<span class="st">"Q34PCSS"</span>,<span class="st">"Q34PCRAW"</span>,<span class="st">"Q34APSS"</span>,<span class="st">"Q34APRAW"</span>,<span class="st">"Q34DSTO"</span>,<span class="st">"BPI_E07"</span>,<span class="st">"BPI_N07"</span>)</span>
<span id="cb25-14"><a href="#cb25-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-15"><a href="#cb25-15" aria-hidden="true" tabindex="-1"></a><span class="co"># separate and recombine files in a panel</span></span>
<span id="cb25-16"><a href="#cb25-16" aria-hidden="true" tabindex="-1"></a>D97 <span class="ot">&lt;-</span> D[,<span class="fu">c</span>(<span class="st">"KID"</span>,names97)]</span>
<span id="cb25-17"><a href="#cb25-17" aria-hidden="true" tabindex="-1"></a><span class="fu">names</span>(D97)[<span class="dv">2</span><span class="sc">:</span><span class="dv">10</span>] <span class="ot">&lt;-</span> col_names</span>
<span id="cb25-18"><a href="#cb25-18" aria-hidden="true" tabindex="-1"></a>D97<span class="sc">$</span>year <span class="ot">&lt;-</span> <span class="dv">1997</span></span>
<span id="cb25-19"><a href="#cb25-19" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-20"><a href="#cb25-20" aria-hidden="true" tabindex="-1"></a>D02 <span class="ot">&lt;-</span> D[,<span class="fu">c</span>(<span class="st">"KID"</span>,names02)]</span>
<span id="cb25-21"><a href="#cb25-21" aria-hidden="true" tabindex="-1"></a><span class="fu">names</span>(D02)[<span class="dv">2</span><span class="sc">:</span><span class="dv">10</span>] <span class="ot">&lt;-</span> col_names</span>
<span id="cb25-22"><a href="#cb25-22" aria-hidden="true" tabindex="-1"></a>D02<span class="sc">$</span>year <span class="ot">&lt;-</span> <span class="dv">2002</span></span>
<span id="cb25-23"><a href="#cb25-23" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-24"><a href="#cb25-24" aria-hidden="true" tabindex="-1"></a>D07 <span class="ot">&lt;-</span> D[,<span class="fu">c</span>(<span class="st">"KID"</span>,names07)]</span>
<span id="cb25-25"><a href="#cb25-25" aria-hidden="true" tabindex="-1"></a><span class="fu">names</span>(D07)[<span class="dv">2</span><span class="sc">:</span><span class="dv">10</span>] <span class="ot">&lt;-</span> col_names</span>
<span id="cb25-26"><a href="#cb25-26" aria-hidden="true" tabindex="-1"></a>D07<span class="sc">$</span>year <span class="ot">&lt;-</span> <span class="dv">2007</span></span>
<span id="cb25-27"><a href="#cb25-27" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-28"><a href="#cb25-28" aria-hidden="true" tabindex="-1"></a>D <span class="ot">&lt;-</span> <span class="fu">rbind</span>(D97,D02,D07) <span class="sc">%&gt;%</span></span>
<span id="cb25-29"><a href="#cb25-29" aria-hidden="true" tabindex="-1"></a>  <span class="fu">as.data.frame</span>()</span>
<span id="cb25-30"><a href="#cb25-30" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-31"><a href="#cb25-31" aria-hidden="true" tabindex="-1"></a><span class="co"># Finally, replace missing values</span></span>
<span id="cb25-32"><a href="#cb25-32" aria-hidden="true" tabindex="-1"></a>missvals <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="dv">999</span>,<span class="dv">99</span>,<span class="dv">999</span>,<span class="dv">99</span>,<span class="dv">999</span>,<span class="dv">99</span>,<span class="dv">99</span>,<span class="dv">99</span>,<span class="dv">99</span>)</span>
<span id="cb25-33"><a href="#cb25-33" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (i <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span><span class="dv">9</span>) {</span>
<span id="cb25-34"><a href="#cb25-34" aria-hidden="true" tabindex="-1"></a>  D[,col_names[i]] <span class="ot">&lt;-</span> <span class="fu">na_if</span>(D[,col_names[i]],missvals[i])</span>
<span id="cb25-35"><a href="#cb25-35" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb25-36"><a href="#cb25-36" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-37"><a href="#cb25-37" aria-hidden="true" tabindex="-1"></a>assessment_panel <span class="ot">&lt;-</span> D</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Assemble a measure of the PCG’s passage comprehension score.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb26"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a>m2 <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/cds/assessments/PCG-PC.xlsx"</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb26-2"><a href="#cb26-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">KID =</span> ER30001<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> ER30002) <span class="sc">%&gt;%</span> </span>
<span id="cb26-3"><a href="#cb26-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(KID,Q1PCSS,Q1PCRAW)<span class="sc">%&gt;%</span></span>
<span id="cb26-4"><a href="#cb26-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">m_pc_st=</span> Q1PCSS, <span class="at">m_pc_raw=</span> Q1PCRAW)</span>
<span id="cb26-5"><a href="#cb26-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb26-6"><a href="#cb26-6" aria-hidden="true" tabindex="-1"></a><span class="co"># load the auxiliary data and create the Kid ID and the PCG ID.</span></span>
<span id="cb26-7"><a href="#cb26-7" aria-hidden="true" tabindex="-1"></a><span class="co"># then merge by Kid ID with the PCG's test score data</span></span>
<span id="cb26-8"><a href="#cb26-8" aria-hidden="true" tabindex="-1"></a><span class="co"># then drop missing observations</span></span>
<span id="cb26-9"><a href="#cb26-9" aria-hidden="true" tabindex="-1"></a>cds <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/CDS-aux-info.xlsx"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb26-10"><a href="#cb26-10" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">KID =</span> CDSCUMID68<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> CDSCUMPN,<span class="at">MID =</span> ID68PCG97<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> PNPCG97) <span class="sc">%&gt;%</span></span>
<span id="cb26-11"><a href="#cb26-11" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(KID,MID) <span class="sc">%&gt;%</span></span>
<span id="cb26-12"><a href="#cb26-12" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(m2) <span class="sc">%&gt;%</span></span>
<span id="cb26-13"><a href="#cb26-13" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(m_pc_st<span class="sc">&gt;</span><span class="dv">0</span>) <span class="sc">%&gt;%</span></span>
<span id="cb26-14"><a href="#cb26-14" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(MID,m_pc_st,m_pc_raw) <span class="sc">%&gt;%</span></span>
<span id="cb26-15"><a href="#cb26-15" aria-hidden="true" tabindex="-1"></a>  <span class="fu">unique</span>()</span>
<span id="cb26-16"><a href="#cb26-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb26-17"><a href="#cb26-17" aria-hidden="true" tabindex="-1"></a><span class="co"># there are a small handful of observations where the raw score is the same but the conversion to standardized score differs slightly, in this case we just keep the first observation</span></span>
<span id="cb26-18"><a href="#cb26-18" aria-hidden="true" tabindex="-1"></a>cds <span class="ot">&lt;-</span> cds <span class="sc">%&gt;%</span></span>
<span id="cb26-19"><a href="#cb26-19" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(MID) <span class="sc">%&gt;%</span></span>
<span id="cb26-20"><a href="#cb26-20" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(<span class="fu">row_number</span>()<span class="sc">==</span><span class="dv">1</span>)</span>
<span id="cb26-21"><a href="#cb26-21" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb26-22"><a href="#cb26-22" aria-hidden="true" tabindex="-1"></a>passage_comprehension <span class="ot">&lt;-</span> cds</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="time-diaries" class="level2">
<h2 class="anchored" data-anchor-id="time-diaries">Time Diaries</h2>
<p>First load the 1997 and 2002 time diaries, clean them, and rename the files so they are consistent across those years. The coding manual for time use activities are <a href="../../../data/data_PSID/docs/codingman.pdf">here</a> and <a href="../../../data/data_PSID/docs/2003codebook.pdf">here.</a>. Inspecting these you will see that the code categories are slightly more fine in the 2002 wave (one extra digit). So for example a category coded as 919 in 1997 becomes 9190 in 2002 or potentially 919<span class="math inline">\(x\)</span> for some <span class="math inline">\(x\in\{1,...,9\}\)</span> depending on the sub-category.</p>
<p>For a consistent sent of categories, we use the 1997 activity codes and round down to the nearest multiple of 10 for 2002 categories. Here is a summary of the variables:</p>
<table class="caption-top table">
<thead>
<tr class="header">
<th style="text-align: left;">Variable</th>
<th style="text-align: left;">Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">COLA</td>
<td style="text-align: left;">Activity Code</td>
</tr>
<tr class="even">
<td style="text-align: left;">DURATION</td>
<td style="text-align: left;">Duration of activity in seconds</td>
</tr>
<tr class="odd">
<td style="text-align: left;">COLG_B</td>
<td style="text-align: left;">Mother participating in activity</td>
</tr>
<tr class="even">
<td style="text-align: left;">COLG_C</td>
<td style="text-align: left;">Father participating in activity</td>
</tr>
<tr class="odd">
<td style="text-align: left;">COLH_B</td>
<td style="text-align: left;">Mother around but not participating</td>
</tr>
<tr class="even">
<td style="text-align: left;">COLH_C</td>
<td style="text-align: left;">Father around but not participating</td>
</tr>
<tr class="odd">
<td style="text-align: left;">COLG_I</td>
<td style="text-align: left;">Grandparent or great-grandparent participating in activity</td>
</tr>
<tr class="even">
<td style="text-align: left;">COLG_J</td>
<td style="text-align: left;">Other relative participating in activity</td>
</tr>
<tr class="odd">
<td style="text-align: left;">COLG_K</td>
<td style="text-align: left;">Other non-relative participating in activity</td>
</tr>
<tr class="even">
<td style="text-align: left;">COLH_I</td>
<td style="text-align: left;">Grandparent or great-grandparent around but not participating</td>
</tr>
<tr class="odd">
<td style="text-align: left;">COLH_J</td>
<td style="text-align: left;">Other relative around but not participating</td>
</tr>
<tr class="even">
<td style="text-align: left;">COLH_K</td>
<td style="text-align: left;">Other non-relative around but not participating</td>
</tr>
<tr class="odd">
<td style="text-align: left;">COLF</td>
<td style="text-align: left;">Where was Child? (40 = babysitter,home-based care,neighbors, 89 = center based care)</td>
</tr>
<tr class="even">
<td style="text-align: left;">WDAYWEND</td>
<td style="text-align: left;">Indicates weekday or weekend</td>
</tr>
</tbody>
</table>
<p>The chunk below imports the data, appends both waves into one dataset (after renaming), and fills in some missing values.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb27"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a><span class="co"># 300-399 is obtaining goods/services (remove?)</span></span>
<span id="cb27-2"><a href="#cb27-2" aria-hidden="true" tabindex="-1"></a><span class="co"># 919 tv</span></span>
<span id="cb27-3"><a href="#cb27-3" aria-hidden="true" tabindex="-1"></a>T0 <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="st">"../../../data/data_PSID/cds/time-diary/TD97full.csv"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb27-4"><a href="#cb27-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">KID=</span>ER30001<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> ER30002,<span class="at">year =</span> <span class="dv">1997</span>) <span class="sc">%&gt;%</span></span>
<span id="cb27-5"><a href="#cb27-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(KID,year,COLA,COLG_B,COLG_C,COLG_I,COLG_J,COLG_K,COLH_B,COLH_C,COLH_I,COLH_J,COLH_K,COLF,WDAYWEND,DURATION, COLJ)</span>
<span id="cb27-6"><a href="#cb27-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb27-7"><a href="#cb27-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb27-8"><a href="#cb27-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb27-9"><a href="#cb27-9" aria-hidden="true" tabindex="-1"></a>T1 <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="st">"../../../data/data_PSID/cds/time-diary/TD02full.csv"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb27-10"><a href="#cb27-10" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">KID=</span>ER30001<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> ER30002,<span class="at">year =</span> <span class="dv">2002</span>) <span class="sc">%&gt;%</span></span>
<span id="cb27-11"><a href="#cb27-11" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">COLG_B =</span> COLGB_02, <span class="at">COLG_C =</span> COLGC_02 , <span class="at">COLG_I =</span> COLGI_02,<span class="at">COLG_J =</span> COLGJ_02,<span class="at">COLG_K =</span> COLGK_02, <span class="at">COLH_B =</span> COLHB_02, <span class="at">COLH_C =</span> COLHC_02, <span class="at">COLH_I =</span> COLHI_02,<span class="at">COLH_J =</span> COLHJ_02,<span class="at">COLH_K =</span> COLHK_02, <span class="at">WDAYWEND =</span> DIARY_02, <span class="at">DURATION =</span> DUR_02, <span class="at">COLA =</span> COLA_02,<span class="at">COLF =</span> COLF_02, <span class="at">COLJ=</span>COLJ_02) <span class="sc">%&gt;%</span></span>
<span id="cb27-12"><a href="#cb27-12" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(KID,year,COLA,COLG_B,COLG_C,COLG_I,COLG_J,COLG_K,COLH_B,COLH_C,COLH_I,COLH_J,COLH_K,COLF,WDAYWEND,DURATION, COLJ) <span class="sc">%&gt;%</span></span>
<span id="cb27-13"><a href="#cb27-13" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">COLA =</span> <span class="fu">floor</span>(COLA<span class="sc">/</span><span class="dv">10</span>)) <span class="co">#&lt;- have to round down</span></span>
<span id="cb27-14"><a href="#cb27-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb27-15"><a href="#cb27-15" aria-hidden="true" tabindex="-1"></a>T2 <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="st">"../../../data/data_PSID/cds/time-diary/TD07full.csv"</span>)<span class="sc">%&gt;%</span></span>
<span id="cb27-16"><a href="#cb27-16" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">KID=</span>ER30001<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> ER30002,<span class="at">year =</span> <span class="dv">2007</span>) <span class="sc">%&gt;%</span></span>
<span id="cb27-17"><a href="#cb27-17" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">COLG_B =</span> COLHB_07, <span class="at">COLG_C =</span> COLHC_07 , <span class="at">COLH_B =</span> COLIB_07, <span class="at">COLH_C =</span> COLIC_07, <span class="at">WDAYWEND =</span> DIARY_07, <span class="at">DURATION =</span> DUR_07, <span class="at">COLA =</span> COLA_07, </span>
<span id="cb27-18"><a href="#cb27-18" aria-hidden="true" tabindex="-1"></a>         <span class="at">COLG_I=</span> COLHI_07  , <span class="at">COLG_J=</span> COLHJ_07, <span class="at">COLG_K=</span> COLHK_07, <span class="at">COLH_I=</span> COLII_07 ,<span class="at">COLH_J=</span> COLIJ_07,<span class="at">COLH_K=</span> COLIK_07,<span class="at">COLF =</span> COLG_07, <span class="at">COLJ=</span>COLJ_07) <span class="sc">%&gt;%</span></span>
<span id="cb27-19"><a href="#cb27-19" aria-hidden="true" tabindex="-1"></a>   <span class="fu">select</span>(KID,year,COLA,COLG_B,COLG_C,COLG_I,COLG_J,COLG_K,COLH_B,COLH_C,COLH_I,COLH_J,COLH_K,COLF,WDAYWEND,DURATION, COLJ) <span class="sc">%&gt;%</span></span>
<span id="cb27-20"><a href="#cb27-20" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">COLG_B =</span> <span class="fu">if_else</span>(COLG_B<span class="sc">==</span><span class="dv">5</span>, <span class="fu">as.integer</span>(<span class="dv">0</span>), <span class="fu">as.integer</span>(COLG_B)),<span class="at">COLG_C =</span> <span class="fu">if_else</span>(COLG_C<span class="sc">==</span><span class="dv">5</span>, <span class="fu">as.integer</span>(<span class="dv">0</span>), <span class="fu">as.integer</span>(COLG_C)),</span>
<span id="cb27-21"><a href="#cb27-21" aria-hidden="true" tabindex="-1"></a>         <span class="at">COLH_B =</span> <span class="fu">if_else</span>(COLH_B<span class="sc">==</span><span class="dv">5</span>, <span class="fu">as.integer</span>(<span class="dv">0</span>), <span class="fu">as.integer</span>(COLH_B)), <span class="at">COLH_C =</span> <span class="fu">if_else</span>(COLH_C<span class="sc">==</span><span class="dv">5</span>, <span class="fu">as.integer</span>(<span class="dv">0</span>), <span class="fu">as.integer</span>(COLH_C)),<span class="co">#&lt;- 5 corresponds to activity being personal, private, school, or work according to the codebook - I make it 0</span></span>
<span id="cb27-22"><a href="#cb27-22" aria-hidden="true" tabindex="-1"></a>         <span class="at">COLA =</span> <span class="fu">floor</span>(COLA<span class="sc">/</span><span class="dv">10</span>), <span class="at">COLJ =</span> <span class="fu">floor</span>(COLJ<span class="sc">/</span><span class="dv">10</span>)) <span class="co">#&lt;- have to round down</span></span>
<span id="cb27-23"><a href="#cb27-23" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb27-24"><a href="#cb27-24" aria-hidden="true" tabindex="-1"></a>TD <span class="ot">&lt;-</span> <span class="fu">rbind</span>(T0,T1,T2) <span class="sc">%&gt;%</span></span>
<span id="cb27-25"><a href="#cb27-25" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">time2ind =</span> COLA<span class="sc">!=</span><span class="dv">919</span>) <span class="sc">%&gt;%</span> <span class="co">#&lt;-</span></span>
<span id="cb27-26"><a href="#cb27-26" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">COLG_B =</span> <span class="fu">na_if</span>(COLG_B,<span class="dv">9</span>),<span class="at">COLG_C =</span> <span class="fu">na_if</span>(COLG_C,<span class="dv">9</span>),<span class="at">COLH_B =</span> <span class="fu">na_if</span>(COLH_B,<span class="dv">9</span>), <span class="at">COLH_C =</span> <span class="fu">na_if</span>(COLH_C,<span class="dv">9</span>),<span class="at">COLG_I =</span> <span class="fu">na_if</span>(COLG_I,<span class="dv">9</span>),<span class="at">COLG_J =</span> <span class="fu">na_if</span>(COLG_J,<span class="dv">9</span>),<span class="at">COLH_K =</span> <span class="fu">na_if</span>(COLH_K,<span class="dv">9</span>),<span class="at">COLH_I =</span> <span class="fu">na_if</span>(COLH_I,<span class="dv">9</span>),<span class="at">COLH_J =</span> <span class="fu">na_if</span>(COLH_J,<span class="dv">9</span>),<span class="at">COLH_K =</span> <span class="fu">na_if</span>(COLH_K,<span class="dv">9</span>)) <span class="co">#&lt;- code in missing categories</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Next, we define a few categories of time use that we will add up for each individual. The comments below describe what each defined variable captures.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb28"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a><span class="co">#create a dummy variable equal to 1 if parents are engaged into the "investment" activity</span></span>
<span id="cb28-2"><a href="#cb28-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-3"><a href="#cb28-3" aria-hidden="true" tabindex="-1"></a>TD<span class="sc">$</span>investment<span class="ot">=</span><span class="fu">ifelse</span>(TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">258</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">222</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">249</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">259</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">238</span><span class="sc">|</span></span>
<span id="cb28-4"><a href="#cb28-4" aria-hidden="true" tabindex="-1"></a>                       TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">339</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">411</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">488</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">501</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">504</span><span class="sc">|</span></span>
<span id="cb28-5"><a href="#cb28-5" aria-hidden="true" tabindex="-1"></a>                       TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">511</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">519</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">549</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">569</span><span class="sc">|</span></span>
<span id="cb28-6"><a href="#cb28-6" aria-hidden="true" tabindex="-1"></a>                       (TD<span class="sc">$</span>COLA<span class="sc">&gt;=</span><span class="dv">709</span><span class="sc">&amp;</span>TD<span class="sc">$</span>COLA<span class="sc">&lt;=</span><span class="dv">749</span>)<span class="sc">|</span>(TD<span class="sc">$</span>COLA<span class="sc">&gt;=</span><span class="dv">801</span><span class="sc">&amp;</span>TD<span class="sc">$</span>COLA<span class="sc">&lt;=</span><span class="dv">889</span>)<span class="sc">|</span></span>
<span id="cb28-7"><a href="#cb28-7" aria-hidden="true" tabindex="-1"></a>                       TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">939</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">941</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">959</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">942</span><span class="sc">|</span></span>
<span id="cb28-8"><a href="#cb28-8" aria-hidden="true" tabindex="-1"></a>                       TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">943</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">962</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">967</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">979</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">963</span>,<span class="dv">1</span>,<span class="dv">0</span>)</span>
<span id="cb28-9"><a href="#cb28-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-10"><a href="#cb28-10" aria-hidden="true" tabindex="-1"></a><span class="co">#create an dummy variable equal to 1 if parents are engaged into the "socializing" activity</span></span>
<span id="cb28-11"><a href="#cb28-11" aria-hidden="true" tabindex="-1"></a>TD<span class="sc">$</span>social<span class="ot">=</span><span class="fu">ifelse</span>(TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">439</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">448</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">449</span><span class="sc">|</span>(TD<span class="sc">$</span>COLA<span class="sc">&gt;=</span><span class="dv">601</span><span class="sc">&amp;</span>TD<span class="sc">$</span>COLA<span class="sc">&lt;=</span><span class="dv">689</span>)<span class="sc">|</span></span>
<span id="cb28-12"><a href="#cb28-12" aria-hidden="true" tabindex="-1"></a>                   TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">752</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">769</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">771</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">772</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">789</span>,<span class="dv">1</span>,<span class="dv">0</span>)</span>
<span id="cb28-13"><a href="#cb28-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-14"><a href="#cb28-14" aria-hidden="true" tabindex="-1"></a><span class="co">#create expanded investment and social dummy variables</span></span>
<span id="cb28-15"><a href="#cb28-15" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-16"><a href="#cb28-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-17"><a href="#cb28-17" aria-hidden="true" tabindex="-1"></a>TD<span class="sc">$</span>ex_soc<span class="ot">=</span><span class="fu">ifelse</span>(TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">108</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">109</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">118</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">119</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">698</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">699</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">799</span><span class="sc">|</span>TD<span class="sc">$</span>social<span class="sc">==</span><span class="dv">1</span>,<span class="dv">1</span>,<span class="dv">0</span>)</span>
<span id="cb28-18"><a href="#cb28-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-19"><a href="#cb28-19" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-20"><a href="#cb28-20" aria-hidden="true" tabindex="-1"></a>TD<span class="sc">$</span>ex_inv<span class="ot">=</span><span class="fu">ifelse</span>(TD<span class="sc">$</span>investment<span class="sc">==</span><span class="dv">1</span><span class="sc">|</span></span>
<span id="cb28-21"><a href="#cb28-21" aria-hidden="true" tabindex="-1"></a>                   TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">248</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">221</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">239</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">377</span><span class="sc">|</span></span>
<span id="cb28-22"><a href="#cb28-22" aria-hidden="true" tabindex="-1"></a>                   TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">484</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">510</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">512</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">599</span><span class="sc">|</span></span>
<span id="cb28-23"><a href="#cb28-23" aria-hidden="true" tabindex="-1"></a>                   TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">597</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">598</span><span class="sc">|</span>TD<span class="sc">$</span>COLA<span class="sc">==</span><span class="dv">899</span>,<span class="dv">1</span>,<span class="dv">0</span>)</span>
<span id="cb28-24"><a href="#cb28-24" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-25"><a href="#cb28-25" aria-hidden="true" tabindex="-1"></a><span class="co"># a dummy if no parent is around </span></span>
<span id="cb28-26"><a href="#cb28-26" aria-hidden="true" tabindex="-1"></a>TD<span class="sc">$</span>no_parent <span class="ot">=</span> (TD<span class="sc">$</span>COLG_B<span class="sc">==</span><span class="dv">0</span>) <span class="sc">&amp;</span> (TD<span class="sc">$</span>COLG_C<span class="sc">==</span><span class="dv">0</span>) <span class="sc">&amp;</span> (TD<span class="sc">$</span>COLH_B<span class="sc">==</span><span class="dv">0</span>) <span class="sc">&amp;</span> (TD<span class="sc">$</span>COLH_C<span class="sc">==</span><span class="dv">0</span>)</span>
<span id="cb28-27"><a href="#cb28-27" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-28"><a href="#cb28-28" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-29"><a href="#cb28-29" aria-hidden="true" tabindex="-1"></a><span class="co"># create a formal, non-relative care variable</span></span>
<span id="cb28-30"><a href="#cb28-30" aria-hidden="true" tabindex="-1"></a>TD<span class="sc">$</span>formal <span class="ot">=</span> TD<span class="sc">$</span>no_parent <span class="sc">&amp;</span> (TD<span class="sc">$</span>COLF<span class="sc">==</span><span class="dv">84</span>)</span>
<span id="cb28-31"><a href="#cb28-31" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-32"><a href="#cb28-32" aria-hidden="true" tabindex="-1"></a><span class="co"># create a relative care variable</span></span>
<span id="cb28-33"><a href="#cb28-33" aria-hidden="true" tabindex="-1"></a>TD<span class="sc">$</span>relative <span class="ot">=</span> TD<span class="sc">$</span>no_parent <span class="sc">&amp;</span> (TD<span class="sc">$</span>COLG_I<span class="sc">==</span><span class="dv">1</span> <span class="sc">|</span> TD<span class="sc">$</span>COLG_J<span class="sc">==</span><span class="dv">1</span> <span class="sc">|</span> TD<span class="sc">$</span>COLH_I<span class="sc">==</span><span class="dv">1</span> <span class="sc">|</span> TD<span class="sc">$</span>COLH_J<span class="sc">==</span><span class="dv">1</span>)</span>
<span id="cb28-34"><a href="#cb28-34" aria-hidden="true" tabindex="-1"></a><span class="co"># create a relative present variable</span></span>
<span id="cb28-35"><a href="#cb28-35" aria-hidden="true" tabindex="-1"></a>TD<span class="sc">$</span>relative_present <span class="ot">=</span> (TD<span class="sc">$</span>COLG_I<span class="sc">==</span><span class="dv">1</span> <span class="sc">|</span> TD<span class="sc">$</span>COLG_J<span class="sc">==</span><span class="dv">1</span> <span class="sc">|</span> TD<span class="sc">$</span>COLH_I<span class="sc">==</span><span class="dv">1</span> <span class="sc">|</span> TD<span class="sc">$</span>COLH_J<span class="sc">==</span><span class="dv">1</span>)</span>
<span id="cb28-36"><a href="#cb28-36" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-37"><a href="#cb28-37" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-38"><a href="#cb28-38" aria-hidden="true" tabindex="-1"></a><span class="co"># create an informal non-relative care variable. Defined as time in non-relative care that does not occur in a formal center and does not occur at school</span></span>
<span id="cb28-39"><a href="#cb28-39" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-40"><a href="#cb28-40" aria-hidden="true" tabindex="-1"></a>TD<span class="sc">$</span>informal <span class="ot">=</span> TD<span class="sc">$</span>no_parent <span class="sc">&amp;</span> <span class="sc">!</span>TD<span class="sc">$</span>relative <span class="sc">&amp;</span> (TD<span class="sc">$</span>COLF<span class="sc">!=</span><span class="dv">84</span>) <span class="sc">&amp;</span> (TD<span class="sc">$</span>COLF<span class="sc">!=</span><span class="dv">80</span>) <span class="sc">&amp;</span> (TD<span class="sc">$</span>COLG_K<span class="sc">==</span><span class="dv">1</span> <span class="sc">|</span> TD<span class="sc">$</span>COLH_K<span class="sc">==</span><span class="dv">1</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>We want a file that for each year and child, contains the total active time for mothers and fathers. Eventually, we also want to look at this disaggregated. We also want to look at total time invested.</p>
<p>When aggregating to a weekly estimate, we’ll add a weight of 5 to weekdays, and 2 to weekends.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb29"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a>TD<span class="sc">$</span>wght <span class="ot">=</span> <span class="dv">2</span> <span class="sc">+</span> <span class="dv">3</span><span class="sc">*</span>TD<span class="sc">$</span>WDAYWEND</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Now we create the means of active time, measured in hours per week. Our main measures, <em>tau_m</em> and <em>tau_f</em>, sum up all activity times with parents actively participating. The alternatives <em>tau_m2</em> and <em>tau_f2</em> do the same thing but exclude TV watching from the list of categories. The other investment categories are defined in the code chunk above.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb30"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a>TD_agg <span class="ot">&lt;-</span> TD <span class="sc">%&gt;%</span> </span>
<span id="cb30-2"><a href="#cb30-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(KID,year) <span class="sc">%&gt;%</span> </span>
<span id="cb30-3"><a href="#cb30-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(<span class="at">tau_m =</span> <span class="fu">sum</span>(DURATION<span class="sc">*</span>wght<span class="sc">*</span>COLG_B,<span class="at">na.rm =</span> <span class="cn">TRUE</span>)<span class="sc">/</span><span class="dv">3600</span>, <span class="at">tau_f =</span> <span class="fu">sum</span>(DURATION<span class="sc">*</span>wght<span class="sc">*</span>COLG_C,<span class="at">na.rm=</span><span class="cn">TRUE</span>)<span class="sc">/</span><span class="dv">3600</span>, <span class="at">tau_both =</span> <span class="fu">sum</span>(DURATION<span class="sc">*</span>wght<span class="sc">*</span>(COLG_B <span class="sc">+</span> (<span class="dv">1</span><span class="sc">-</span>COLG_B)<span class="sc">*</span>COLG_C),<span class="at">na.rm=</span><span class="cn">TRUE</span>)<span class="sc">/</span><span class="dv">3600</span>, <span class="at">tau_m2 =</span> <span class="fu">sum</span>(time2ind<span class="sc">*</span>DURATION<span class="sc">*</span>wght<span class="sc">*</span>COLG_B,<span class="at">na.rm =</span> <span class="cn">TRUE</span>)<span class="sc">/</span><span class="dv">3600</span>, <span class="at">tau_f2 =</span> <span class="fu">sum</span>(time2ind<span class="sc">*</span>DURATION<span class="sc">*</span>wght<span class="sc">*</span>COLG_C,<span class="at">na.rm=</span><span class="cn">TRUE</span>)<span class="sc">/</span><span class="dv">3600</span>,</span>
<span id="cb30-4"><a href="#cb30-4" aria-hidden="true" tabindex="-1"></a>            <span class="at">tau_m_investment =</span> <span class="fu">sum</span>(DURATION<span class="sc">*</span>wght<span class="sc">*</span>COLG_B<span class="sc">*</span>investment,<span class="at">na.rm =</span> <span class="cn">TRUE</span>)<span class="sc">/</span><span class="dv">3600</span>,  <span class="at">tau_m_social =</span> <span class="fu">sum</span>(DURATION<span class="sc">*</span>wght<span class="sc">*</span>COLG_B<span class="sc">*</span>social,<span class="at">na.rm =</span> <span class="cn">TRUE</span>)<span class="sc">/</span><span class="dv">3600</span>, <span class="at">tau_m_ex_inv =</span> <span class="fu">sum</span>(DURATION<span class="sc">*</span>wght<span class="sc">*</span>COLG_B<span class="sc">*</span>ex_inv,<span class="at">na.rm =</span> <span class="cn">TRUE</span>)<span class="sc">/</span><span class="dv">3600</span>,  <span class="at">tau_m_ex_soc =</span> <span class="fu">sum</span>(DURATION<span class="sc">*</span>wght<span class="sc">*</span>COLG_B<span class="sc">*</span>ex_soc,<span class="at">na.rm =</span> <span class="cn">TRUE</span>)<span class="sc">/</span><span class="dv">3600</span>, </span>
<span id="cb30-5"><a href="#cb30-5" aria-hidden="true" tabindex="-1"></a>            <span class="at">tau_f_investment =</span> <span class="fu">sum</span>(DURATION<span class="sc">*</span>wght<span class="sc">*</span>COLG_C<span class="sc">*</span>investment,<span class="at">na.rm =</span> <span class="cn">TRUE</span>)<span class="sc">/</span><span class="dv">3600</span>,  <span class="at">tau_f_social =</span> <span class="fu">sum</span>(DURATION<span class="sc">*</span>wght<span class="sc">*</span>COLG_C<span class="sc">*</span>social,<span class="at">na.rm =</span> <span class="cn">TRUE</span>)<span class="sc">/</span><span class="dv">3600</span>, <span class="at">tau_f_ex_inv =</span> <span class="fu">sum</span>(DURATION<span class="sc">*</span>wght<span class="sc">*</span>COLG_C<span class="sc">*</span>ex_inv,<span class="at">na.rm =</span> <span class="cn">TRUE</span>)<span class="sc">/</span><span class="dv">3600</span>, <span class="at">tau_f_ex_soc =</span> <span class="fu">sum</span>(DURATION<span class="sc">*</span>wght<span class="sc">*</span>COLG_C<span class="sc">*</span>ex_soc,<span class="at">na.rm =</span> <span class="cn">TRUE</span>)<span class="sc">/</span><span class="dv">3600</span>,</span>
<span id="cb30-6"><a href="#cb30-6" aria-hidden="true" tabindex="-1"></a>            <span class="at">tau_both_investment =</span> <span class="fu">sum</span>(DURATION<span class="sc">*</span>wght<span class="sc">*</span>(COLG_B <span class="sc">+</span> (<span class="dv">1</span><span class="sc">-</span>COLG_B)<span class="sc">*</span>COLG_C)<span class="sc">*</span>investment,<span class="at">na.rm =</span> <span class="cn">TRUE</span>)<span class="sc">/</span><span class="dv">3600</span>,  <span class="at">tau_both_social =</span> <span class="fu">sum</span>(DURATION<span class="sc">*</span>wght<span class="sc">*</span>(COLG_B <span class="sc">+</span> (<span class="dv">1</span><span class="sc">-</span>COLG_B)<span class="sc">*</span>COLG_C)<span class="sc">*</span>social,<span class="at">na.rm =</span> <span class="cn">TRUE</span>)<span class="sc">/</span><span class="dv">3600</span>, <span class="at">tau_both_ex_inv =</span> <span class="fu">sum</span>(DURATION<span class="sc">*</span>wght<span class="sc">*</span>(COLG_B <span class="sc">+</span> (<span class="dv">1</span><span class="sc">-</span>COLG_B)<span class="sc">*</span>COLG_C)<span class="sc">*</span>ex_inv,<span class="at">na.rm =</span> <span class="cn">TRUE</span>)<span class="sc">/</span><span class="dv">3600</span>, <span class="at">tau_both_ex_soc =</span> <span class="fu">sum</span>(DURATION<span class="sc">*</span>wght<span class="sc">*</span>(COLG_B <span class="sc">+</span> (<span class="dv">1</span><span class="sc">-</span>COLG_B)<span class="sc">*</span>COLG_C)<span class="sc">*</span>ex_soc,<span class="at">na.rm =</span> <span class="cn">TRUE</span>)<span class="sc">/</span><span class="dv">3600</span>,</span>
<span id="cb30-7"><a href="#cb30-7" aria-hidden="true" tabindex="-1"></a>            <span class="at">formal =</span> <span class="fu">sum</span>(DURATION<span class="sc">*</span>wght<span class="sc">*</span>formal,<span class="at">na.rm =</span> <span class="cn">TRUE</span>)<span class="sc">/</span><span class="dv">3600</span>,<span class="at">informal =</span> <span class="fu">sum</span>(DURATION<span class="sc">*</span>wght<span class="sc">*</span>informal,<span class="at">na.rm =</span> <span class="cn">TRUE</span>)<span class="sc">/</span><span class="dv">3600</span>,<span class="at">relative =</span> <span class="fu">sum</span>(DURATION<span class="sc">*</span>wght<span class="sc">*</span>relative,<span class="at">na.rm =</span> <span class="cn">TRUE</span>)<span class="sc">/</span><span class="dv">3600</span>,<span class="at">relative_present =</span> <span class="fu">sum</span>(DURATION<span class="sc">*</span>wght<span class="sc">*</span>relative_present,<span class="at">na.rm =</span> <span class="cn">TRUE</span>)<span class="sc">/</span><span class="dv">3600</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>`summarise()` has grouped output by 'KID'. You can override using the `.groups`
argument.</code></pre>
</div>
<div class="sourceCode cell-code" id="cb32"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb32-1"><a href="#cb32-1" aria-hidden="true" tabindex="-1"></a><span class="co">#Create expanded social and expanded investment measure</span></span>
<span id="cb32-2"><a href="#cb32-2" aria-hidden="true" tabindex="-1"></a>TD_agg <span class="ot">&lt;-</span> TD_agg <span class="sc">%&gt;%</span> </span>
<span id="cb32-3"><a href="#cb32-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">tau_m_socinvest=</span>tau_m_ex_inv<span class="sc">+</span>tau_m_ex_soc,</span>
<span id="cb32-4"><a href="#cb32-4" aria-hidden="true" tabindex="-1"></a>         <span class="at">tau_f_socinvest=</span>tau_f_ex_inv<span class="sc">+</span>tau_f_ex_soc,</span>
<span id="cb32-5"><a href="#cb32-5" aria-hidden="true" tabindex="-1"></a>         <span class="at">tau_both_socinvest=</span>tau_both_ex_inv<span class="sc">+</span>tau_both_ex_soc)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Read the frequency of gatherings with family and friends.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb33"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb33-1"><a href="#cb33-1" aria-hidden="true" tabindex="-1"></a>fr97 <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/cds/time-diary/family_friends/family_friends.xlsx"</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb33-2"><a href="#cb33-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">KID=</span>ER30001<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> ER30002,<span class="at">year =</span> <span class="dv">1997</span>, <span class="at">Q1B7=</span><span class="fu">case_when</span>(Q1B7<span class="sc">&gt;=</span><span class="dv">8</span> <span class="sc">~</span> <span class="cn">NA_real_</span>, <span class="cn">TRUE</span> <span class="sc">~</span>Q1B7),</span>
<span id="cb33-3"><a href="#cb33-3" aria-hidden="true" tabindex="-1"></a>         <span class="at">live_grand=</span><span class="fu">case_when</span>(BIOGPR97<span class="sc">==</span><span class="dv">1</span> <span class="sc">~</span> <span class="dv">1</span>,BIOGPR97<span class="sc">==</span><span class="dv">2</span> <span class="sc">~</span> <span class="dv">0</span>,BIOGPR97<span class="sc">==</span><span class="dv">3</span> <span class="sc">~</span> <span class="dv">0</span>, <span class="cn">TRUE</span> <span class="sc">~</span> <span class="cn">NA_real_</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb33-4"><a href="#cb33-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(KID, year,Q1B7,live_grand)<span class="sc">%&gt;%</span></span>
<span id="cb33-5"><a href="#cb33-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">freq_family=</span>Q1B7)</span>
<span id="cb33-6"><a href="#cb33-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb33-7"><a href="#cb33-7" aria-hidden="true" tabindex="-1"></a><span class="co">#use grandparents living/not living with child in 2001 for 2002 (2003 is also available)</span></span>
<span id="cb33-8"><a href="#cb33-8" aria-hidden="true" tabindex="-1"></a>fr02 <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/cds/time-diary/family_friends/family_friends.xlsx"</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb33-9"><a href="#cb33-9" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">KID=</span>ER30001<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> ER30002,<span class="at">year =</span> <span class="dv">2002</span>, <span class="at">Q21E6=</span><span class="fu">case_when</span>(Q21E6<span class="sc">&gt;=</span><span class="dv">8</span> <span class="sc">~</span> <span class="cn">NA_real_</span>, <span class="cn">TRUE</span> <span class="sc">~</span>Q21E6),</span>
<span id="cb33-10"><a href="#cb33-10" aria-hidden="true" tabindex="-1"></a>        <span class="at">live_grand=</span><span class="fu">case_when</span>(BIOGPR01<span class="sc">==</span><span class="dv">1</span> <span class="sc">~</span> <span class="dv">1</span>,BIOGPR01<span class="sc">==</span><span class="dv">2</span> <span class="sc">~</span> <span class="dv">0</span>,BIOGPR01<span class="sc">==</span><span class="dv">3</span> <span class="sc">~</span> <span class="dv">0</span>,BIOGPR01<span class="sc">==</span><span class="dv">4</span> <span class="sc">~</span> <span class="dv">0</span>, <span class="cn">TRUE</span> <span class="sc">~</span> <span class="cn">NA_real_</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb33-11"><a href="#cb33-11" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(KID, year,Q21E6,live_grand)<span class="sc">%&gt;%</span></span>
<span id="cb33-12"><a href="#cb33-12" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">freq_family=</span>Q21E6)</span>
<span id="cb33-13"><a href="#cb33-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb33-14"><a href="#cb33-14" aria-hidden="true" tabindex="-1"></a>fr07 <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/cds/time-diary/family_friends/family_friends.xlsx"</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb33-15"><a href="#cb33-15" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">KID=</span>ER30001<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> ER30002,<span class="at">year =</span> <span class="dv">2007</span>, <span class="at">Q31E6=</span><span class="fu">case_when</span>(Q31E6<span class="sc">&gt;=</span><span class="dv">8</span> <span class="sc">~</span> <span class="cn">NA_real_</span>, <span class="cn">TRUE</span> <span class="sc">~</span>Q31E6),</span>
<span id="cb33-16"><a href="#cb33-16" aria-hidden="true" tabindex="-1"></a>              <span class="at">live_grand=</span><span class="fu">case_when</span>(BIOGPR07<span class="sc">==</span><span class="dv">1</span> <span class="sc">~</span> <span class="dv">1</span>,BIOGPR07<span class="sc">==</span><span class="dv">2</span> <span class="sc">~</span> <span class="dv">0</span>,BIOGPR07<span class="sc">==</span><span class="dv">3</span> <span class="sc">~</span> <span class="dv">0</span>,BIOGPR07<span class="sc">==</span><span class="dv">4</span> <span class="sc">~</span> <span class="dv">0</span>, <span class="cn">TRUE</span> <span class="sc">~</span> <span class="cn">NA_real_</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb33-17"><a href="#cb33-17" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(KID, year,Q31E6,live_grand)<span class="sc">%&gt;%</span></span>
<span id="cb33-18"><a href="#cb33-18" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">freq_family=</span>Q31E6)</span>
<span id="cb33-19"><a href="#cb33-19" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb33-20"><a href="#cb33-20" aria-hidden="true" tabindex="-1"></a><span class="co">#stack into a panel</span></span>
<span id="cb33-21"><a href="#cb33-21" aria-hidden="true" tabindex="-1"></a>fr <span class="ot">&lt;-</span> <span class="fu">rbind</span>(fr97,fr02,fr07)</span>
<span id="cb33-22"><a href="#cb33-22" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb33-23"><a href="#cb33-23" aria-hidden="true" tabindex="-1"></a><span class="co">#merge with panel of time</span></span>
<span id="cb33-24"><a href="#cb33-24" aria-hidden="true" tabindex="-1"></a>TD_agg <span class="ot">&lt;-</span> TD_agg <span class="sc">%&gt;%</span></span>
<span id="cb33-25"><a href="#cb33-25" aria-hidden="true" tabindex="-1"></a>  <span class="fu">left_join</span>(fr)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Joining with `by = join_by(KID, year)`</code></pre>
</div>
</div>
</section>
<section id="expenditures" class="level2">
<h2 class="anchored" data-anchor-id="expenditures">Expenditures</h2>
<div class="cell">
<div class="sourceCode cell-code" id="cb35"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb35-1"><a href="#cb35-1" aria-hidden="true" tabindex="-1"></a>E <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="st">"../../../data/data_PSID/cds/expenditures/Exp_0207.csv"</span>)</span>
<span id="cb35-2"><a href="#cb35-2" aria-hidden="true" tabindex="-1"></a><span class="co">#generate kid's ID</span></span>
<span id="cb35-3"><a href="#cb35-3" aria-hidden="true" tabindex="-1"></a>E <span class="ot">&lt;-</span> E <span class="sc">%&gt;%</span></span>
<span id="cb35-4"><a href="#cb35-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">KID =</span> ER30001<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> ER30002)</span>
<span id="cb35-5"><a href="#cb35-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb35-6"><a href="#cb35-6" aria-hidden="true" tabindex="-1"></a><span class="co">#First select kids in 2002 sample and variables describing 2002 hh expenditures</span></span>
<span id="cb35-7"><a href="#cb35-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb35-8"><a href="#cb35-8" aria-hidden="true" tabindex="-1"></a>E02<span class="ot">&lt;-</span>E[E<span class="sc">$</span>KID02<span class="sc">==</span><span class="fl">1.1</span>,] <span class="sc">%&gt;%</span><span class="fu">select</span>(KID,<span class="fu">starts_with</span>(<span class="st">"Q21"</span>))</span>
<span id="cb35-9"><a href="#cb35-9" aria-hidden="true" tabindex="-1"></a><span class="co">#Substitute to missing if the primary caregiver did not know about costs</span></span>
<span id="cb35-10"><a href="#cb35-10" aria-hidden="true" tabindex="-1"></a>E02[(E02<span class="sc">$</span>Q21H23A<span class="sc">&gt;=</span><span class="dv">8</span><span class="sc">|</span><span class="fu">is.na</span>(E02<span class="sc">$</span>Q21H23A)<span class="sc">==</span><span class="dv">1</span><span class="sc">|</span>E02<span class="sc">$</span>Q21H23A1<span class="sc">&gt;=</span><span class="dv">99998</span>),<span class="st">"Q21H23A1"</span>]<span class="ot">&lt;-</span><span class="cn">NA</span></span>
<span id="cb35-11"><a href="#cb35-11" aria-hidden="true" tabindex="-1"></a>E02[(E02<span class="sc">$</span>Q21H23B<span class="sc">&gt;=</span><span class="dv">8</span><span class="sc">|</span><span class="fu">is.na</span>(E02<span class="sc">$</span>Q21H23B)<span class="sc">==</span><span class="dv">1</span><span class="sc">|</span>E02<span class="sc">$</span>Q21H23B1<span class="sc">&gt;=</span><span class="dv">99998</span>),<span class="st">"Q21H23B1"</span>]<span class="ot">&lt;-</span><span class="cn">NA</span></span>
<span id="cb35-12"><a href="#cb35-12" aria-hidden="true" tabindex="-1"></a>E02[(E02<span class="sc">$</span>Q21H23C<span class="sc">&gt;=</span><span class="dv">8</span><span class="sc">|</span><span class="fu">is.na</span>(E02<span class="sc">$</span>Q21H23C)<span class="sc">==</span><span class="dv">1</span><span class="sc">|</span>E02<span class="sc">$</span>Q21H23C1<span class="sc">&gt;=</span><span class="dv">9998</span>),<span class="st">"Q21H23C1"</span>]<span class="ot">&lt;-</span><span class="cn">NA</span></span>
<span id="cb35-13"><a href="#cb35-13" aria-hidden="true" tabindex="-1"></a>E02[(E02<span class="sc">$</span>Q21H23D<span class="sc">&gt;=</span><span class="dv">8</span><span class="sc">|</span><span class="fu">is.na</span>(E02<span class="sc">$</span>Q21H23D)<span class="sc">==</span><span class="dv">1</span><span class="sc">|</span>E02<span class="sc">$</span>Q21H23D1<span class="sc">&gt;=</span><span class="dv">9998</span>),<span class="st">"Q21H23D1"</span>]<span class="ot">&lt;-</span><span class="cn">NA</span></span>
<span id="cb35-14"><a href="#cb35-14" aria-hidden="true" tabindex="-1"></a>E02[(E02<span class="sc">$</span>Q21H23H<span class="sc">&gt;=</span><span class="dv">8</span><span class="sc">|</span><span class="fu">is.na</span>(E02<span class="sc">$</span>Q21H23H)<span class="sc">==</span><span class="dv">1</span><span class="sc">|</span>E02<span class="sc">$</span>Q21H23H1<span class="sc">&gt;=</span><span class="dv">99998</span>),<span class="st">"Q21H23H1"</span>]<span class="ot">&lt;-</span><span class="cn">NA</span></span>
<span id="cb35-15"><a href="#cb35-15" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb35-16"><a href="#cb35-16" aria-hidden="true" tabindex="-1"></a>E02 <span class="ot">&lt;-</span> E02 <span class="sc">%&gt;%</span></span>
<span id="cb35-17"><a href="#cb35-17" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">Toys =</span> Q21H23A1, <span class="at">Vacation =</span> Q21H23B1, <span class="at">SchSupplies =</span> Q21H23C1, <span class="at">Clothing =</span> Q21H23D1, <span class="at">Food =</span> Q21H23H1) <span class="sc">%&gt;%</span></span>
<span id="cb35-18"><a href="#cb35-18" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">Toys =</span> Toys<span class="sc">/</span><span class="dv">52</span>, <span class="at">Vacation =</span> Vacation<span class="sc">/</span><span class="dv">52</span>, <span class="at">SchSupplies =</span> SchSupplies<span class="sc">/</span><span class="dv">52</span>, <span class="at">Clothing =</span> Clothing<span class="sc">/</span><span class="dv">52</span>, <span class="at">Food =</span> Food<span class="sc">/</span><span class="dv">52</span>)</span>
<span id="cb35-19"><a href="#cb35-19" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb35-20"><a href="#cb35-20" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb35-21"><a href="#cb35-21" aria-hidden="true" tabindex="-1"></a><span class="co">#Substitute to missing if the primary caregiver did not know about costs</span></span>
<span id="cb35-22"><a href="#cb35-22" aria-hidden="true" tabindex="-1"></a>E02<span class="sc">$</span>Q21G5D[(E02<span class="sc">$</span>Q21G5D<span class="sc">&gt;=</span><span class="dv">9998</span>)] <span class="ot">&lt;-</span> <span class="cn">NA</span></span>
<span id="cb35-23"><a href="#cb35-23" aria-hidden="true" tabindex="-1"></a>E02<span class="sc">$</span>Q21H5C[(E02<span class="sc">$</span>Q21H5C<span class="sc">&gt;=</span><span class="dv">9998</span>)] <span class="ot">&lt;-</span> <span class="cn">NA</span></span>
<span id="cb35-24"><a href="#cb35-24" aria-hidden="true" tabindex="-1"></a>E02<span class="sc">$</span>Q21G10C[(E02<span class="sc">$</span>Q21G10C<span class="sc">&gt;=</span><span class="dv">9998</span>)] <span class="ot">&lt;-</span> <span class="cn">NA</span></span>
<span id="cb35-25"><a href="#cb35-25" aria-hidden="true" tabindex="-1"></a>E02<span class="sc">$</span>Q21H8B[(E02<span class="sc">$</span>Q21H8B<span class="sc">&gt;=</span><span class="dv">9998</span>)] <span class="ot">&lt;-</span> <span class="cn">NA</span></span>
<span id="cb35-26"><a href="#cb35-26" aria-hidden="true" tabindex="-1"></a>E02<span class="sc">$</span>Q21G8I[(E02<span class="sc">$</span>Q21G8I<span class="sc">&gt;=</span><span class="dv">9998</span>)] <span class="ot">&lt;-</span> <span class="cn">NA</span></span>
<span id="cb35-27"><a href="#cb35-27" aria-hidden="true" tabindex="-1"></a>E02<span class="sc">$</span>Q21H7F[(E02<span class="sc">$</span>Q21H7F<span class="sc">&gt;=</span><span class="dv">9998</span>)] <span class="ot">&lt;-</span> <span class="cn">NA</span></span>
<span id="cb35-28"><a href="#cb35-28" aria-hidden="true" tabindex="-1"></a>E02<span class="sc">$</span>Q21G7C [(E02<span class="sc">$</span>Q21G7C <span class="sc">&gt;=</span><span class="dv">9998</span>)] <span class="ot">&lt;-</span> <span class="cn">NA</span></span>
<span id="cb35-29"><a href="#cb35-29" aria-hidden="true" tabindex="-1"></a>E02<span class="sc">$</span>Q21H6B[(E02<span class="sc">$</span>Q21H6B<span class="sc">&gt;=</span><span class="dv">9998</span>)] <span class="ot">&lt;-</span> <span class="cn">NA</span></span>
<span id="cb35-30"><a href="#cb35-30" aria-hidden="true" tabindex="-1"></a>E02<span class="sc">$</span>Q21B12A1[(E02<span class="sc">$</span>Q21B12A1<span class="sc">&gt;=</span><span class="dv">99998</span>)] <span class="ot">&lt;-</span> <span class="cn">NA</span></span>
<span id="cb35-31"><a href="#cb35-31" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb35-32"><a href="#cb35-32" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb35-33"><a href="#cb35-33" aria-hidden="true" tabindex="-1"></a><span class="co">#Combine expenditure on children in diffenet age groups, generate annual tuition cost</span></span>
<span id="cb35-34"><a href="#cb35-34" aria-hidden="true" tabindex="-1"></a>E02 <span class="ot">&lt;-</span> E02 <span class="sc">%&gt;%</span></span>
<span id="cb35-35"><a href="#cb35-35" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">2002</span> ) <span class="sc">%&gt;%</span></span>
<span id="cb35-36"><a href="#cb35-36" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">tutoring =</span> Q21G5D <span class="sc">+</span> Q21H5C) <span class="sc">%&gt;%</span></span>
<span id="cb35-37"><a href="#cb35-37" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">comm_grps =</span> (Q21G10C <span class="sc">+</span> Q21H8B)) <span class="sc">%&gt;%</span></span>
<span id="cb35-38"><a href="#cb35-38" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">sports =</span> (Q21G8I <span class="sc">+</span> Q21H7F)) <span class="sc">%&gt;%</span></span>
<span id="cb35-39"><a href="#cb35-39" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">lessons =</span> (Q21G7C <span class="sc">+</span> Q21H6B)) <span class="sc">%&gt;%</span></span>
<span id="cb35-40"><a href="#cb35-40" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">tuition =</span> Q21B12A1)<span class="sc">%&gt;%</span></span>
<span id="cb35-41"><a href="#cb35-41" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">tuition =</span> <span class="fu">case_when</span>(Q21B12A2<span class="sc">==</span><span class="dv">3</span> <span class="sc">~</span> <span class="dv">50</span><span class="sc">*</span><span class="fu">as.numeric</span>(tuition),Q21B12A2<span class="sc">==</span><span class="dv">5</span> <span class="sc">~</span> <span class="dv">12</span><span class="sc">*</span><span class="fu">as.numeric</span>(tuition), <span class="cn">TRUE</span> <span class="sc">~</span> <span class="fu">as.numeric</span>(tuition)))<span class="sc">%&gt;%</span></span>
<span id="cb35-42"><a href="#cb35-42" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(KID, year, tuition, lessons, tutoring, comm_grps, sports, Toys, Vacation, SchSupplies, Clothing, Food)</span>
<span id="cb35-43"><a href="#cb35-43" aria-hidden="true" tabindex="-1"></a>    </span>
<span id="cb35-44"><a href="#cb35-44" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb35-45"><a href="#cb35-45" aria-hidden="true" tabindex="-1"></a><span class="co">#Select kids in 2007 sample and variables describing 2007 hh expenditures</span></span>
<span id="cb35-46"><a href="#cb35-46" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb35-47"><a href="#cb35-47" aria-hidden="true" tabindex="-1"></a>E07<span class="ot">&lt;-</span>E[E<span class="sc">$</span>KID07<span class="sc">==</span><span class="fl">1.1</span>,] <span class="sc">%&gt;%</span><span class="fu">select</span>(KID,<span class="fu">starts_with</span>(<span class="st">"Q31"</span>))</span>
<span id="cb35-48"><a href="#cb35-48" aria-hidden="true" tabindex="-1"></a><span class="co">#Substitute to missing if the primary caregiver did not not about costs</span></span>
<span id="cb35-49"><a href="#cb35-49" aria-hidden="true" tabindex="-1"></a>E07[(E07<span class="sc">$</span>Q31H23A<span class="sc">&gt;=</span><span class="dv">8</span><span class="sc">|</span><span class="fu">is.na</span>(E07<span class="sc">$</span>Q31H23A)<span class="sc">==</span><span class="dv">1</span><span class="sc">|</span>E07<span class="sc">$</span>Q31H23A1<span class="sc">&gt;=</span><span class="dv">99998</span>),<span class="st">"Q31H23A1"</span>]<span class="ot">&lt;-</span><span class="cn">NA</span></span>
<span id="cb35-50"><a href="#cb35-50" aria-hidden="true" tabindex="-1"></a>E07[(E07<span class="sc">$</span>Q31H23B<span class="sc">&gt;=</span><span class="dv">8</span><span class="sc">|</span><span class="fu">is.na</span>(E07<span class="sc">$</span>Q31H23B)<span class="sc">==</span><span class="dv">1</span><span class="sc">|</span>E07<span class="sc">$</span>Q31H23B1<span class="sc">&gt;=</span><span class="dv">99998</span>),<span class="st">"Q31H23B1"</span>]<span class="ot">&lt;-</span><span class="cn">NA</span></span>
<span id="cb35-51"><a href="#cb35-51" aria-hidden="true" tabindex="-1"></a>E07[(E07<span class="sc">$</span>Q31H23C<span class="sc">&gt;=</span><span class="dv">8</span><span class="sc">|</span><span class="fu">is.na</span>(E07<span class="sc">$</span>Q31H23C)<span class="sc">==</span><span class="dv">1</span><span class="sc">|</span>E07<span class="sc">$</span>Q31H23C1<span class="sc">&gt;=</span><span class="dv">99998</span>),<span class="st">"Q31H23C1"</span>]<span class="ot">&lt;-</span><span class="cn">NA</span></span>
<span id="cb35-52"><a href="#cb35-52" aria-hidden="true" tabindex="-1"></a>E07[(E07<span class="sc">$</span>Q31H23D<span class="sc">&gt;=</span><span class="dv">8</span><span class="sc">|</span><span class="fu">is.na</span>(E07<span class="sc">$</span>Q31H23D)<span class="sc">==</span><span class="dv">1</span><span class="sc">|</span>E07<span class="sc">$</span>Q31H23D1<span class="sc">&gt;=</span><span class="dv">99998</span>),<span class="st">"Q31H23D1"</span>]<span class="ot">&lt;-</span><span class="cn">NA</span></span>
<span id="cb35-53"><a href="#cb35-53" aria-hidden="true" tabindex="-1"></a>E07[(E07<span class="sc">$</span>Q31H23H<span class="sc">&gt;=</span><span class="dv">8</span><span class="sc">|</span><span class="fu">is.na</span>(E07<span class="sc">$</span>Q31H23H)<span class="sc">==</span><span class="dv">1</span><span class="sc">|</span>E07<span class="sc">$</span>Q31H23H1<span class="sc">&gt;=</span><span class="dv">99998</span>),<span class="st">"Q31H23H1"</span>]<span class="ot">&lt;-</span><span class="cn">NA</span></span>
<span id="cb35-54"><a href="#cb35-54" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb35-55"><a href="#cb35-55" aria-hidden="true" tabindex="-1"></a>E07 <span class="ot">&lt;-</span> E07 <span class="sc">%&gt;%</span></span>
<span id="cb35-56"><a href="#cb35-56" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">Toys =</span> Q31H23A1, <span class="at">Vacation =</span> Q31H23B1, <span class="at">SchSupplies =</span> Q31H23C1, <span class="at">Clothing =</span> Q31H23D1, <span class="at">Food =</span> Q31H23H1) <span class="sc">%&gt;%</span></span>
<span id="cb35-57"><a href="#cb35-57" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">Toys =</span> Toys<span class="sc">/</span><span class="dv">52</span>, <span class="at">Vacation =</span> Vacation<span class="sc">/</span><span class="dv">52</span>, <span class="at">SchSupplies =</span> SchSupplies<span class="sc">/</span><span class="dv">52</span>, <span class="at">Clothing =</span> Clothing<span class="sc">/</span><span class="dv">52</span>, <span class="at">Food =</span> <span class="cn">NA</span>)</span>
<span id="cb35-58"><a href="#cb35-58" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb35-59"><a href="#cb35-59" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb35-60"><a href="#cb35-60" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb35-61"><a href="#cb35-61" aria-hidden="true" tabindex="-1"></a>E07<span class="sc">$</span>Q31H5C[(E07<span class="sc">$</span>Q31H5C<span class="sc">&gt;=</span><span class="dv">9998</span>)] <span class="ot">&lt;-</span> <span class="cn">NA</span></span>
<span id="cb35-62"><a href="#cb35-62" aria-hidden="true" tabindex="-1"></a>E07<span class="sc">$</span>Q31H8B[(E07<span class="sc">$</span>Q31H8B<span class="sc">&gt;=</span><span class="dv">9998</span>)] <span class="ot">&lt;-</span> <span class="cn">NA</span></span>
<span id="cb35-63"><a href="#cb35-63" aria-hidden="true" tabindex="-1"></a>E07<span class="sc">$</span>Q31H7F[(E07<span class="sc">$</span>Q31H7F<span class="sc">&gt;=</span><span class="dv">9998</span>)] <span class="ot">&lt;-</span> <span class="cn">NA</span></span>
<span id="cb35-64"><a href="#cb35-64" aria-hidden="true" tabindex="-1"></a>E07<span class="sc">$</span>Q31H6B[(E07<span class="sc">$</span>Q31H6B<span class="sc">&gt;=</span><span class="dv">9998</span>)] <span class="ot">&lt;-</span> <span class="cn">NA</span></span>
<span id="cb35-65"><a href="#cb35-65" aria-hidden="true" tabindex="-1"></a>E07<span class="sc">$</span>Q31B12A1[(E07<span class="sc">$</span>Q31B12A1<span class="sc">&gt;=</span><span class="dv">99998</span>)] <span class="ot">&lt;-</span> <span class="cn">NA</span></span>
<span id="cb35-66"><a href="#cb35-66" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb35-67"><a href="#cb35-67" aria-hidden="true" tabindex="-1"></a><span class="co">#In 2007 children the information is collected for children 10+, generate annual tuition cost</span></span>
<span id="cb35-68"><a href="#cb35-68" aria-hidden="true" tabindex="-1"></a>E07 <span class="ot">&lt;-</span> E07 <span class="sc">%&gt;%</span></span>
<span id="cb35-69"><a href="#cb35-69" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">2007</span>) <span class="sc">%&gt;%</span></span>
<span id="cb35-70"><a href="#cb35-70" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">tutoring =</span> Q31H5C) <span class="sc">%&gt;%</span></span>
<span id="cb35-71"><a href="#cb35-71" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">comm_grps =</span> Q31H8B) <span class="sc">%&gt;%</span></span>
<span id="cb35-72"><a href="#cb35-72" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">sports =</span> Q31H7F) <span class="sc">%&gt;%</span></span>
<span id="cb35-73"><a href="#cb35-73" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">lessons =</span> Q31H6B) <span class="sc">%&gt;%</span></span>
<span id="cb35-74"><a href="#cb35-74" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">tuition =</span> Q31B12A1)<span class="sc">%&gt;%</span></span>
<span id="cb35-75"><a href="#cb35-75" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">tuition =</span> <span class="fu">case_when</span>(Q31B12A2<span class="sc">==</span><span class="dv">3</span> <span class="sc">~</span> <span class="dv">50</span><span class="sc">*</span><span class="fu">as.numeric</span>(tuition),Q31B12A2<span class="sc">==</span><span class="dv">5</span> <span class="sc">~</span> <span class="dv">12</span><span class="sc">*</span><span class="fu">as.numeric</span>(tuition), <span class="cn">TRUE</span> <span class="sc">~</span> <span class="fu">as.numeric</span>(tuition)))<span class="sc">%&gt;%</span></span>
<span id="cb35-76"><a href="#cb35-76" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(KID,year,Toys,Vacation,SchSupplies,Clothing,Food,sports,lessons,comm_grps,tutoring,tuition)</span>
<span id="cb35-77"><a href="#cb35-77" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb35-78"><a href="#cb35-78" aria-hidden="true" tabindex="-1"></a><span class="co">#Merge 2002 and 2007 expenditure data, transform annual expenditures to weekly</span></span>
<span id="cb35-79"><a href="#cb35-79" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb35-80"><a href="#cb35-80" aria-hidden="true" tabindex="-1"></a>E <span class="ot">&lt;-</span> <span class="fu">rbind</span>(E07, E02)</span>
<span id="cb35-81"><a href="#cb35-81" aria-hidden="true" tabindex="-1"></a>E<span class="ot">=</span>E<span class="sc">%&gt;%</span><span class="fu">mutate</span>(<span class="at">tuition=</span>tuition<span class="sc">/</span><span class="dv">52</span>, </span>
<span id="cb35-82"><a href="#cb35-82" aria-hidden="true" tabindex="-1"></a>         <span class="at">comm_grps=</span>comm_grps<span class="sc">/</span><span class="dv">52</span>,</span>
<span id="cb35-83"><a href="#cb35-83" aria-hidden="true" tabindex="-1"></a>         <span class="at">lessons=</span>lessons<span class="sc">/</span><span class="dv">52</span>,</span>
<span id="cb35-84"><a href="#cb35-84" aria-hidden="true" tabindex="-1"></a>         <span class="at">tutoring=</span>tutoring<span class="sc">/</span><span class="dv">52</span>,</span>
<span id="cb35-85"><a href="#cb35-85" aria-hidden="true" tabindex="-1"></a>         <span class="at">sports=</span>sports<span class="sc">/</span><span class="dv">52</span>)</span>
<span id="cb35-86"><a href="#cb35-86" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb35-87"><a href="#cb35-87" aria-hidden="true" tabindex="-1"></a><span class="co">#Drop children with missing ID</span></span>
<span id="cb35-88"><a href="#cb35-88" aria-hidden="true" tabindex="-1"></a>E <span class="ot">&lt;-</span> E[<span class="fu">is.na</span>(E<span class="sc">$</span>KID)<span class="sc">==</span><span class="dv">0</span>,]</span>
<span id="cb35-89"><a href="#cb35-89" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb35-90"><a href="#cb35-90" aria-hidden="true" tabindex="-1"></a>cols <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">"KID"</span>,<span class="st">"year"</span>,<span class="st">"Toys"</span>,<span class="st">"Vacation"</span>,<span class="st">"SchSupplies"</span>,<span class="st">"Clothing"</span>,<span class="st">"Food"</span>,<span class="st">"sports"</span>,<span class="st">"lessons"</span>,<span class="st">"comm_grps"</span>,<span class="st">"tutoring"</span>,<span class="st">"tuition"</span>)</span>
<span id="cb35-91"><a href="#cb35-91" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb35-92"><a href="#cb35-92" aria-hidden="true" tabindex="-1"></a>cds_expenditures <span class="ot">&lt;-</span> E[,cols]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<section id="per-pupil-expenditures" class="level3">
<h3 class="anchored" data-anchor-id="per-pupil-expenditures">Per Pupil Expenditures</h3>
<p>When possible, as part of the CDS supplement, the PSID conducted interviews with the Middle and Elementary School administrators. The data below cleans all available data on reported per pupil expenditure for the school.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb36"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb36-1"><a href="#cb36-1" aria-hidden="true" tabindex="-1"></a>PPE <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/cds/expenditures/CDS_PPE.xlsx"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb36-2"><a href="#cb36-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">KID =</span> ER30001<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> ER30002) <span class="sc">%&gt;%</span></span>
<span id="cb36-3"><a href="#cb36-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">PPE =</span> Q12A27) <span class="sc">%&gt;%</span></span>
<span id="cb36-4"><a href="#cb36-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">PPE =</span> <span class="fu">case_when</span>(PPE<span class="sc">&lt;</span><span class="dv">99998</span> <span class="sc">~</span> PPE)) <span class="sc">%&gt;%</span> <span class="co">#&lt;- code in missing values</span></span>
<span id="cb36-5"><a href="#cb36-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(KID,PPE) <span class="sc">%&gt;%</span></span>
<span id="cb36-6"><a href="#cb36-6" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> <span class="dv">1997</span>) <span class="co">#&lt;- add the year for merging into a panel.</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
</section>
<section id="childcare-expenditures" class="level2">
<h2 class="anchored" data-anchor-id="childcare-expenditures">Childcare Expenditures</h2>
<p>In 2002/2007, the interview distinguishes between weekday and weekend care options (which the 1997 wave does not). Since there were very few responses to the weekend care question, we are just using weekday care. In addition, since there were very few responses given beyond the 1st care option, we are only using those data.</p>
<p>For convenience the 1997 variables are that we use are tabulated below.</p>
<table class="caption-top table">
<thead>
<tr class="header">
<th style="text-align: left;">Vname</th>
<th style="text-align: left;">Variable Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">ER30001</td>
<td style="text-align: left;">1968 INTERVIEW NUMBER</td>
</tr>
<tr class="even">
<td style="text-align: left;">ER30002</td>
<td style="text-align: left;">PERSON NUMBER 68</td>
</tr>
<tr class="odd">
<td style="text-align: left;">ER33401</td>
<td style="text-align: left;">1997 INTERVIEW NUMBER</td>
</tr>
<tr class="even">
<td style="text-align: left;">Q1H14</td>
<td style="text-align: left;">MOST USED ARRNGMNT 97</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Q1H15</td>
<td style="text-align: left;">2ND ARRNGMNT MOST USED 97</td>
</tr>
<tr class="even">
<td style="text-align: left;">Q1H18</td>
<td style="text-align: left;">USUAL ARRNGMNT-DAYS PER WEEK 97</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Q1H19</td>
<td style="text-align: left;">USUAL ARRNGMNT-HRS PER WEEK 97</td>
</tr>
<tr class="even">
<td style="text-align: left;">Q1H21</td>
<td style="text-align: left;">USUAL ARRNGMNT-COST 97</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Q1H21A</td>
<td style="text-align: left;">USUAL ARRNGMNT-PAYMENT RATE 97</td>
</tr>
<tr class="even">
<td style="text-align: left;">Q1H22</td>
<td style="text-align: left;">USUAL ARRNGMNT-OTHER CHILDREN 97</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Q1H22A</td>
<td style="text-align: left;">USUAL ARRNGMNT-# OF OTHER CHILDREN 97</td>
</tr>
<tr class="even">
<td style="text-align: left;">Q1H24</td>
<td style="text-align: left;">2ND ARRNGMNT-DAYS PER WEEK 97</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Q1H25</td>
<td style="text-align: left;">2ND ARRNGMNT-HRS PER WEEK 97</td>
</tr>
<tr class="even">
<td style="text-align: left;">Q1H27</td>
<td style="text-align: left;">2ND ARRNGMNT-COST 97</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Q1H27A</td>
<td style="text-align: left;">2ND ARRNGMNT-PAYMENT RATE 97</td>
</tr>
<tr class="even">
<td style="text-align: left;">Q1H28</td>
<td style="text-align: left;">2ND ARRNGMNT-OTHER CHILDREN 97</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Q1H28A</td>
<td style="text-align: left;">2ND ARRNGMNT-# OF OTHER CHILDREN 97</td>
</tr>
</tbody>
</table>
<p>For now, let’s just create data on expenditures for each year. In 1997, the cost was reported in one of several units: (1) hourly (2) daily (3) weekly (4) fortnightly (5) monthly (6) annual. We standardize this into a weekly measure. We also derive an hourly price using the weekly cost and hours per week, as well as an indicator for the type of arrangement being used.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb37"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb37-1"><a href="#cb37-1" aria-hidden="true" tabindex="-1"></a>Ch97 <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/cds/childcare/chcare_9707.xlsx"</span>) <span class="sc">%&gt;%</span> <span class="co">#&lt;- read in the data</span></span>
<span id="cb37-2"><a href="#cb37-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">KID =</span> ER30001<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> ER30002) <span class="sc">%&gt;%</span></span>
<span id="cb37-3"><a href="#cb37-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">Q1H21 =</span> <span class="fu">case_when</span>(Q1H21<span class="sc">&lt;</span><span class="dv">9998</span> <span class="sc">~</span> Q1H21),<span class="at">Q1H18 =</span> <span class="fu">case_when</span>(Q1H18<span class="sc">&lt;</span><span class="dv">8</span> <span class="sc">~</span> Q1H18),<span class="at">Q1H19=</span><span class="fu">case_when</span>(Q1H19<span class="sc">&lt;</span><span class="dv">998</span> <span class="sc">~</span> Q1H19),<span class="at">Q1H21A=</span><span class="fu">case_when</span>(Q1H21A<span class="sc">&lt;</span><span class="dv">8</span> <span class="sc">~</span> Q1H21A)) <span class="sc">%&gt;%</span> <span class="co">#&lt;- fill in missing values </span></span>
<span id="cb37-4"><a href="#cb37-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">Q1H27 =</span> <span class="fu">case_when</span>(Q1H27<span class="sc">&lt;</span><span class="dv">9998</span> <span class="sc">~</span>Q1H27 ),<span class="at">Q1H24=</span> <span class="fu">case_when</span>(Q1H24<span class="sc">&lt;</span><span class="dv">8</span> <span class="sc">~</span> Q1H24),<span class="at">Q1H25=</span><span class="fu">case_when</span>(Q1H25<span class="sc">&lt;</span><span class="dv">98</span> <span class="sc">~</span> Q1H25),<span class="at">Q1H27A=</span><span class="fu">case_when</span>(Q1H27A<span class="sc">&lt;</span><span class="dv">8</span> <span class="sc">~</span> Q1H27A)) <span class="sc">%&gt;%</span> <span class="co">#&lt;- fill in missing values for second arrangement</span></span>
<span id="cb37-5"><a href="#cb37-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">chcareExp97 =</span> <span class="fu">case_when</span>(Q1H21A<span class="sc">==</span><span class="dv">1</span> <span class="sc">~</span> Q1H21<span class="sc">*</span>Q1H19, <span class="co">#, #&lt;- cost reported hourly</span></span>
<span id="cb37-6"><a href="#cb37-6" aria-hidden="true" tabindex="-1"></a>                                 Q1H21A<span class="sc">==</span><span class="dv">2</span> <span class="sc">~</span> Q1H21<span class="sc">*</span>Q1H18,  <span class="co">#&lt;- reported daily</span></span>
<span id="cb37-7"><a href="#cb37-7" aria-hidden="true" tabindex="-1"></a>                                 Q1H21A<span class="sc">==</span><span class="dv">4</span> <span class="sc">~</span> Q1H21<span class="sc">/</span><span class="dv">2</span>, <span class="co">#&lt;- reported fortnightly</span></span>
<span id="cb37-8"><a href="#cb37-8" aria-hidden="true" tabindex="-1"></a>                                 Q1H21A<span class="sc">==</span><span class="dv">5</span> <span class="sc">~</span> Q1H21<span class="sc">/</span>(<span class="dv">52</span><span class="sc">/</span><span class="dv">12</span>), <span class="co">#&lt;- reported monthly</span></span>
<span id="cb37-9"><a href="#cb37-9" aria-hidden="true" tabindex="-1"></a>                                 Q1H21A<span class="sc">==</span><span class="dv">6</span> <span class="sc">~</span> Q1H21<span class="sc">/</span><span class="dv">52</span>, <span class="co">#&lt;-reported annually</span></span>
<span id="cb37-10"><a href="#cb37-10" aria-hidden="true" tabindex="-1"></a>                                 <span class="cn">TRUE</span> <span class="sc">~</span> Q1H21)) <span class="sc">%&gt;%</span> <span class="co">#&lt;- reported weekly</span></span>
<span id="cb37-11"><a href="#cb37-11" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">chcareExpSecond97 =</span> <span class="fu">case_when</span>(Q1H27A<span class="sc">==</span><span class="dv">1</span> <span class="sc">~</span> Q1H27<span class="sc">*</span>Q1H25, <span class="co">#, #&lt;- cost reported hourly</span></span>
<span id="cb37-12"><a href="#cb37-12" aria-hidden="true" tabindex="-1"></a>                                 Q1H27A<span class="sc">==</span><span class="dv">2</span> <span class="sc">~</span> Q1H27<span class="sc">*</span>Q1H24,  <span class="co">#&lt;- reported daily</span></span>
<span id="cb37-13"><a href="#cb37-13" aria-hidden="true" tabindex="-1"></a>                                 Q1H27A<span class="sc">==</span><span class="dv">4</span> <span class="sc">~</span> Q1H27<span class="sc">/</span><span class="dv">2</span>, <span class="co">#&lt;- reported fortnightly</span></span>
<span id="cb37-14"><a href="#cb37-14" aria-hidden="true" tabindex="-1"></a>                                 Q1H27A<span class="sc">==</span><span class="dv">5</span> <span class="sc">~</span> Q1H27<span class="sc">/</span>(<span class="dv">52</span><span class="sc">/</span><span class="dv">12</span>), <span class="co">#&lt;- reported monthly</span></span>
<span id="cb37-15"><a href="#cb37-15" aria-hidden="true" tabindex="-1"></a>                                 Q1H27A<span class="sc">==</span><span class="dv">6</span> <span class="sc">~</span> Q1H27<span class="sc">/</span><span class="dv">52</span>, <span class="co">#&lt;-reported annually</span></span>
<span id="cb37-16"><a href="#cb37-16" aria-hidden="true" tabindex="-1"></a>                                 <span class="cn">TRUE</span> <span class="sc">~</span> Q1H27)) <span class="sc">%&gt;%</span> <span class="co">#&lt;- reported weekly</span></span>
<span id="cb37-17"><a href="#cb37-17" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">Price97 =</span> chcareExp97<span class="sc">/</span>Q1H19) <span class="sc">%&gt;%</span> <span class="co">#&lt;- derive price</span></span>
<span id="cb37-18"><a href="#cb37-18" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">PriceSecond97 =</span> chcareExpSecond97<span class="sc">/</span>Q1H25) <span class="sc">%&gt;%</span> <span class="co">#&lt;- derive price</span></span>
<span id="cb37-19"><a href="#cb37-19" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">Arrange97 =</span> <span class="fu">case_when</span>(Q1H14<span class="sc">==</span><span class="dv">1</span> <span class="sc">|</span> Q1H14<span class="sc">==</span><span class="dv">2</span> <span class="sc">|</span> Q1H14<span class="sc">==</span><span class="dv">4</span> <span class="sc">~</span> <span class="st">"Relative"</span>,</span>
<span id="cb37-20"><a href="#cb37-20" aria-hidden="true" tabindex="-1"></a>                               Q1H14<span class="sc">==</span><span class="dv">3</span> <span class="sc">~</span> <span class="st">"Non Relative"</span>,</span>
<span id="cb37-21"><a href="#cb37-21" aria-hidden="true" tabindex="-1"></a>                               Q1H14<span class="sc">==</span><span class="dv">5</span> <span class="sc">~</span> <span class="st">"Family Center"</span>,</span>
<span id="cb37-22"><a href="#cb37-22" aria-hidden="true" tabindex="-1"></a>                               Q1H14<span class="sc">==</span><span class="dv">7</span> <span class="sc">~</span> <span class="st">"Care Center"</span>,</span>
<span id="cb37-23"><a href="#cb37-23" aria-hidden="true" tabindex="-1"></a>                               Q1H14<span class="sc">==</span><span class="dv">8</span> <span class="sc">~</span> <span class="st">"Before/After School Prog."</span>))<span class="sc">%&gt;%</span> </span>
<span id="cb37-24"><a href="#cb37-24" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">ArrangeSecond97 =</span> <span class="fu">case_when</span>(Q1H15<span class="sc">==</span><span class="dv">1</span> <span class="sc">|</span> Q1H15<span class="sc">==</span><span class="dv">2</span> <span class="sc">|</span> Q1H15<span class="sc">==</span><span class="dv">4</span> <span class="sc">~</span> <span class="st">"Relative"</span>,</span>
<span id="cb37-25"><a href="#cb37-25" aria-hidden="true" tabindex="-1"></a>                               Q1H15<span class="sc">==</span><span class="dv">3</span> <span class="sc">~</span> <span class="st">"Non Relative"</span>,</span>
<span id="cb37-26"><a href="#cb37-26" aria-hidden="true" tabindex="-1"></a>                               Q1H15<span class="sc">==</span><span class="dv">5</span> <span class="sc">~</span> <span class="st">"Family Center"</span>,</span>
<span id="cb37-27"><a href="#cb37-27" aria-hidden="true" tabindex="-1"></a>                               Q1H15<span class="sc">==</span><span class="dv">7</span> <span class="sc">~</span> <span class="st">"Care Center"</span>,</span>
<span id="cb37-28"><a href="#cb37-28" aria-hidden="true" tabindex="-1"></a>                               Q1H15<span class="sc">==</span><span class="dv">8</span> <span class="sc">~</span> <span class="st">"Before/After School Prog."</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>The chunk of code below does the same thing for the 2002 PCG interview. For reference, here are the variables.</p>
<table class="caption-top table">
<thead>
<tr class="header">
<th style="text-align: left;">Vname</th>
<th style="text-align: left;">Variable Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">ER33601</td>
<td style="text-align: left;">2001 INTERVIEW NUMBER</td>
</tr>
<tr class="even">
<td style="text-align: left;">ER33602</td>
<td style="text-align: left;">SEQUENCE NUMBER 01</td>
</tr>
<tr class="odd">
<td style="text-align: left;">ER33603</td>
<td style="text-align: left;">RELATION TO HEAD 01</td>
</tr>
<tr class="even">
<td style="text-align: left;">CHREL</td>
<td style="text-align: left;">PCG CHILD FILE RELEASE NUMBER 02</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Q21C12</td>
<td style="text-align: left;">WKDAY: CARE USED MOST 02</td>
</tr>
<tr class="even">
<td style="text-align: left;">Q21C13</td>
<td style="text-align: left;">WKDAY: HRS PER WK 02</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Q21C15A</td>
<td style="text-align: left;">WKDAY: COST OF CARE - AMT 02</td>
</tr>
<tr class="even">
<td style="text-align: left;">Q21C15B</td>
<td style="text-align: left;">WKDAY: COST OF CARE - UNIT 02</td>
</tr>
<tr class="odd">
<td style="text-align: left;">ER33901</td>
<td style="text-align: left;">2007 INTERVIEW NUMBER</td>
</tr>
<tr class="even">
<td style="text-align: left;">ER33902</td>
<td style="text-align: left;">SEQUENCE NUMBER 07</td>
</tr>
<tr class="odd">
<td style="text-align: left;">ER33903</td>
<td style="text-align: left;">RELATION TO HEAD 07</td>
</tr>
<tr class="even">
<td style="text-align: left;">PCHREL07</td>
<td style="text-align: left;">PCG CHILD FILE RELEASE NUMBER 07</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Q31C12</td>
<td style="text-align: left;">WKDAY: CARE USED MOST 07</td>
</tr>
<tr class="even">
<td style="text-align: left;">Q31C13</td>
<td style="text-align: left;">WKDAY: HRS PER WK 07</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Q31C15A</td>
<td style="text-align: left;">WKDAY: COST OF CARE - AMT 07</td>
</tr>
<tr class="even">
<td style="text-align: left;">Q31C15B</td>
<td style="text-align: left;">WKDAY: COST OF CARE - UNIT 07</td>
</tr>
</tbody>
</table>
<p>Unlike in 1997, there is no variable that reports the number of days per week. Therefore, to impute the weekly cost when a daily rate is reported, we use the average number of hours per day reported among those that use an hourly rate, and combine this with the hours per week report to get the number of days.</p>
<p>From 1997, we calculate the average number of hours per day as:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb38"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb38-1"><a href="#cb38-1" aria-hidden="true" tabindex="-1"></a>hours_per_day <span class="ot">&lt;-</span> Ch97 <span class="sc">%&gt;%</span> <span class="fu">filter</span>(Q1H18<span class="sc">&gt;</span><span class="dv">0</span>) <span class="sc">%&gt;%</span> <span class="fu">summarise</span>(<span class="fu">mean</span>(Q1H19<span class="sc">/</span>Q1H18,<span class="at">na.rm =</span> <span class="cn">TRUE</span>))</span>
<span id="cb38-2"><a href="#cb38-2" aria-hidden="true" tabindex="-1"></a>hours_per_day[<span class="dv">1</span>,<span class="dv">1</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 1 × 1
  `mean(Q1H19/Q1H18, na.rm = TRUE)`
                              &lt;dbl&gt;
1                              3.09</code></pre>
</div>
</div>
<p>So we get that childcare is used on average for about 3.1 hours per day. The imputed number of days per week is therefore</p>
<p>[Days/Week = (Hours/Week)/(Hours/Day) = (Hours/Week)/3.1]</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb40"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb40-1"><a href="#cb40-1" aria-hidden="true" tabindex="-1"></a>Ch02 <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/cds/childcare/chcare_9707.xlsx"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb40-2"><a href="#cb40-2" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">KID =</span> ER30001<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> ER30002) <span class="sc">%&gt;%</span></span>
<span id="cb40-3"><a href="#cb40-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">Q21C15A =</span> <span class="fu">case_when</span>(Q21C15A<span class="sc">&lt;</span><span class="dv">9998</span> <span class="sc">~</span> Q21C15A),<span class="at">Q21C13=</span><span class="fu">case_when</span>(Q21C13<span class="sc">&lt;</span><span class="dv">998</span> <span class="sc">~</span> Q21C13),<span class="at">Q21C15B=</span><span class="fu">case_when</span>(Q21C15B<span class="sc">&lt;</span><span class="dv">8</span> <span class="sc">~</span> Q21C15B)) <span class="sc">%&gt;%</span> <span class="co">#&lt;- fill in missing values </span></span>
<span id="cb40-4"><a href="#cb40-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">Q21C21A =</span> <span class="fu">case_when</span>(Q21C21A<span class="sc">&lt;</span><span class="dv">998</span> <span class="sc">~</span> Q21C21A),<span class="at">Q21C19=</span><span class="fu">case_when</span>(Q21C19<span class="sc">&lt;</span><span class="dv">998</span> <span class="sc">~</span> Q21C19),<span class="at">Q21C21B=</span><span class="fu">case_when</span>(Q21C21B<span class="sc">&lt;</span><span class="dv">8</span> <span class="sc">~</span> Q21C21B)) <span class="sc">%&gt;%</span> <span class="co">#&lt;- fill in missing values for second childcare measure</span></span>
<span id="cb40-5"><a href="#cb40-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">chcareExp02 =</span> <span class="fu">case_when</span>(Q21C15B<span class="sc">==</span><span class="dv">1</span> <span class="sc">~</span> Q21C15A<span class="sc">*</span>Q21C13, <span class="co">#&lt;- cost reported hourly</span></span>
<span id="cb40-6"><a href="#cb40-6" aria-hidden="true" tabindex="-1"></a>                                 Q21C15B<span class="sc">==</span><span class="dv">2</span> <span class="sc">~</span> Q21C15A<span class="sc">*</span>Q21C13<span class="sc">/</span><span class="fl">3.1</span>, <span class="co">#&lt;- reported daily?</span></span>
<span id="cb40-7"><a href="#cb40-7" aria-hidden="true" tabindex="-1"></a>                                 Q21C15B<span class="sc">==</span><span class="dv">4</span> <span class="sc">~</span> Q21C15A<span class="sc">/</span><span class="dv">2</span>, <span class="co">#&lt;- reported fortnightly</span></span>
<span id="cb40-8"><a href="#cb40-8" aria-hidden="true" tabindex="-1"></a>                                 Q21C15B<span class="sc">==</span><span class="dv">5</span> <span class="sc">~</span> Q21C15A<span class="sc">/</span>(<span class="dv">52</span><span class="sc">/</span><span class="dv">12</span>), <span class="co">#&lt;- reported monthly</span></span>
<span id="cb40-9"><a href="#cb40-9" aria-hidden="true" tabindex="-1"></a>                                 Q21C15B<span class="sc">==</span><span class="dv">6</span> <span class="sc">~</span> Q21C15A<span class="sc">/</span><span class="dv">52</span>,<span class="co">#&lt;-reported annually</span></span>
<span id="cb40-10"><a href="#cb40-10" aria-hidden="true" tabindex="-1"></a>                                 <span class="cn">TRUE</span> <span class="sc">~</span> Q21C15A)) <span class="sc">%&gt;%</span> <span class="co">#&lt;- reported weekly</span></span>
<span id="cb40-11"><a href="#cb40-11" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">chcareExpSecond02 =</span> <span class="fu">case_when</span>(Q21C21B<span class="sc">==</span><span class="dv">1</span> <span class="sc">~</span> Q21C21A<span class="sc">*</span>Q21C19, <span class="co">#&lt;- cost reported hourly</span></span>
<span id="cb40-12"><a href="#cb40-12" aria-hidden="true" tabindex="-1"></a>                                 Q21C21B<span class="sc">==</span><span class="dv">2</span> <span class="sc">~</span> Q21C21A<span class="sc">*</span>Q21C19<span class="sc">/</span><span class="fl">3.1</span>, <span class="co">#&lt;- reported daily?</span></span>
<span id="cb40-13"><a href="#cb40-13" aria-hidden="true" tabindex="-1"></a>                                 Q21C21B<span class="sc">==</span><span class="dv">4</span> <span class="sc">~</span> Q21C21A<span class="sc">/</span><span class="dv">2</span>, <span class="co">#&lt;- reported fortnightly</span></span>
<span id="cb40-14"><a href="#cb40-14" aria-hidden="true" tabindex="-1"></a>                                 Q21C21B<span class="sc">==</span><span class="dv">5</span> <span class="sc">~</span> Q21C21A<span class="sc">/</span>(<span class="dv">52</span><span class="sc">/</span><span class="dv">12</span>), <span class="co">#&lt;- reported monthly</span></span>
<span id="cb40-15"><a href="#cb40-15" aria-hidden="true" tabindex="-1"></a>                                 Q21C21B<span class="sc">==</span><span class="dv">6</span> <span class="sc">~</span> Q21C21A<span class="sc">/</span><span class="dv">52</span>,<span class="co">#&lt;-reported annually</span></span>
<span id="cb40-16"><a href="#cb40-16" aria-hidden="true" tabindex="-1"></a>                                 <span class="cn">TRUE</span> <span class="sc">~</span> Q21C21A)) <span class="sc">%&gt;%</span> <span class="co">#&lt;- reported weekly</span></span>
<span id="cb40-17"><a href="#cb40-17" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">Price02 =</span> chcareExp02<span class="sc">/</span>Q21C13) <span class="sc">%&gt;%</span> <span class="co">#&lt;- derive hourly price</span></span>
<span id="cb40-18"><a href="#cb40-18" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">PriceSecond02 =</span> chcareExpSecond02<span class="sc">/</span>Q21C19) <span class="sc">%&gt;%</span> <span class="co">#&lt;- derive hourly price</span></span>
<span id="cb40-19"><a href="#cb40-19" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">Arrange02 =</span> <span class="fu">case_when</span>(Q21C12<span class="sc">==</span><span class="dv">1</span> <span class="sc">|</span> Q21C12<span class="sc">==</span><span class="dv">2</span>  <span class="sc">~</span> <span class="st">"Relative"</span>,</span>
<span id="cb40-20"><a href="#cb40-20" aria-hidden="true" tabindex="-1"></a>                               Q21C12<span class="sc">==</span><span class="dv">3</span> <span class="sc">~</span> <span class="st">"Non Relative"</span>,</span>
<span id="cb40-21"><a href="#cb40-21" aria-hidden="true" tabindex="-1"></a>                               Q21C12<span class="sc">==</span><span class="dv">5</span> <span class="sc">~</span> <span class="st">"Family Center"</span>,</span>
<span id="cb40-22"><a href="#cb40-22" aria-hidden="true" tabindex="-1"></a>                               Q21C12<span class="sc">==</span><span class="dv">7</span> <span class="sc">~</span> <span class="st">"Care Center"</span>,</span>
<span id="cb40-23"><a href="#cb40-23" aria-hidden="true" tabindex="-1"></a>                               Q21C12<span class="sc">==</span><span class="dv">8</span> <span class="sc">~</span> <span class="st">"Before/After School Prog."</span>))<span class="sc">%&gt;%</span></span>
<span id="cb40-24"><a href="#cb40-24" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">ArrangeSecond02 =</span> <span class="fu">case_when</span>(Q21C18<span class="sc">==</span><span class="dv">1</span> <span class="sc">|</span> Q21C18<span class="sc">==</span><span class="dv">2</span>  <span class="sc">~</span> <span class="st">"Relative"</span>,</span>
<span id="cb40-25"><a href="#cb40-25" aria-hidden="true" tabindex="-1"></a>                               Q21C18<span class="sc">==</span><span class="dv">3</span> <span class="sc">~</span> <span class="st">"Non Relative"</span>,</span>
<span id="cb40-26"><a href="#cb40-26" aria-hidden="true" tabindex="-1"></a>                               Q21C18<span class="sc">==</span><span class="dv">5</span> <span class="sc">~</span> <span class="st">"Family Center"</span>,</span>
<span id="cb40-27"><a href="#cb40-27" aria-hidden="true" tabindex="-1"></a>                               Q21C18<span class="sc">==</span><span class="dv">7</span> <span class="sc">~</span> <span class="st">"Care Center"</span>,</span>
<span id="cb40-28"><a href="#cb40-28" aria-hidden="true" tabindex="-1"></a>                               Q21C18<span class="sc">==</span><span class="dv">8</span> <span class="sc">~</span> <span class="st">"Before/After School Prog."</span>))</span>
<span id="cb40-29"><a href="#cb40-29" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-30"><a href="#cb40-30" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-31"><a href="#cb40-31" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-32"><a href="#cb40-32" aria-hidden="true" tabindex="-1"></a>Ch07 <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/cds/childcare/chcare_9707.xlsx"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb40-33"><a href="#cb40-33" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">KID =</span> ER30001<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> ER30002) <span class="sc">%&gt;%</span></span>
<span id="cb40-34"><a href="#cb40-34" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">Q31C15A =</span> <span class="fu">case_when</span>(Q31C15A<span class="sc">&lt;</span><span class="dv">9998</span> <span class="sc">~</span> Q31C15A),<span class="at">Q31C13=</span><span class="fu">case_when</span>(Q31C13<span class="sc">&lt;</span><span class="dv">998</span> <span class="sc">~</span> Q31C13),<span class="at">Q31C15B=</span><span class="fu">case_when</span>(Q31C15B<span class="sc">&lt;</span><span class="dv">8</span> <span class="sc">~</span> Q31C15B)) <span class="sc">%&gt;%</span> <span class="co">#&lt;- fill in missing values </span></span>
<span id="cb40-35"><a href="#cb40-35" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">Q31C21A =</span> <span class="fu">case_when</span>(Q31C21A<span class="sc">&lt;</span><span class="dv">998</span> <span class="sc">~</span> Q31C21A),<span class="at">Q31C19=</span><span class="fu">case_when</span>(Q31C19<span class="sc">&lt;</span><span class="dv">998</span> <span class="sc">~</span> Q31C19),<span class="at">Q31C21B=</span><span class="fu">case_when</span>(Q31C21B<span class="sc">&lt;</span><span class="dv">8</span> <span class="sc">~</span> Q31C21B)) <span class="sc">%&gt;%</span> <span class="co">#&lt;- fill in missing values for second childcare measure</span></span>
<span id="cb40-36"><a href="#cb40-36" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">chcareExp07 =</span> <span class="fu">case_when</span>(Q31C15B<span class="sc">==</span><span class="dv">1</span> <span class="sc">~</span> Q31C15A<span class="sc">*</span>Q31C13, <span class="co">#&lt;- cost reported hourly</span></span>
<span id="cb40-37"><a href="#cb40-37" aria-hidden="true" tabindex="-1"></a>                                 Q31C15B<span class="sc">==</span><span class="dv">2</span> <span class="sc">~</span> Q31C15A<span class="sc">*</span>Q31C13<span class="sc">/</span><span class="fl">3.1</span>, <span class="co">#&lt;- reported daily?</span></span>
<span id="cb40-38"><a href="#cb40-38" aria-hidden="true" tabindex="-1"></a>                                 Q31C15B<span class="sc">==</span><span class="dv">4</span> <span class="sc">~</span> Q31C15A<span class="sc">/</span><span class="dv">2</span>, <span class="co">#&lt;- reported fortnightly</span></span>
<span id="cb40-39"><a href="#cb40-39" aria-hidden="true" tabindex="-1"></a>                                 Q31C15B<span class="sc">==</span><span class="dv">5</span> <span class="sc">~</span> Q31C15A<span class="sc">/</span>(<span class="dv">52</span><span class="sc">/</span><span class="dv">12</span>), <span class="co">#&lt;- reported monthly</span></span>
<span id="cb40-40"><a href="#cb40-40" aria-hidden="true" tabindex="-1"></a>                                 Q31C15B<span class="sc">==</span><span class="dv">6</span> <span class="sc">~</span> Q31C15A<span class="sc">/</span><span class="dv">52</span>,<span class="co">#&lt;-reported annually</span></span>
<span id="cb40-41"><a href="#cb40-41" aria-hidden="true" tabindex="-1"></a>                                 <span class="cn">TRUE</span> <span class="sc">~</span> Q31C15A)) <span class="sc">%&gt;%</span> <span class="co">#&lt;- reported weekly</span></span>
<span id="cb40-42"><a href="#cb40-42" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">chcareExpSecond07 =</span> <span class="fu">case_when</span>(Q31C21B<span class="sc">==</span><span class="dv">1</span> <span class="sc">~</span> Q31C21A<span class="sc">*</span>Q31C19, <span class="co">#&lt;- cost reported hourly</span></span>
<span id="cb40-43"><a href="#cb40-43" aria-hidden="true" tabindex="-1"></a>                                 Q31C21B<span class="sc">==</span><span class="dv">2</span> <span class="sc">~</span> Q31C21A<span class="sc">*</span>Q31C19<span class="sc">/</span><span class="fl">3.1</span>, <span class="co">#&lt;- reported daily?</span></span>
<span id="cb40-44"><a href="#cb40-44" aria-hidden="true" tabindex="-1"></a>                                 Q31C21B<span class="sc">==</span><span class="dv">4</span> <span class="sc">~</span> Q31C21A<span class="sc">/</span><span class="dv">2</span>, <span class="co">#&lt;- reported fortnightly</span></span>
<span id="cb40-45"><a href="#cb40-45" aria-hidden="true" tabindex="-1"></a>                                 Q31C21B<span class="sc">==</span><span class="dv">5</span> <span class="sc">~</span> Q31C21A<span class="sc">/</span>(<span class="dv">52</span><span class="sc">/</span><span class="dv">12</span>), <span class="co">#&lt;- reported monthly</span></span>
<span id="cb40-46"><a href="#cb40-46" aria-hidden="true" tabindex="-1"></a>                                 Q31C21B<span class="sc">==</span><span class="dv">6</span> <span class="sc">~</span> Q31C21A<span class="sc">/</span><span class="dv">52</span>,<span class="co">#&lt;-reported annually</span></span>
<span id="cb40-47"><a href="#cb40-47" aria-hidden="true" tabindex="-1"></a>                                 <span class="cn">TRUE</span> <span class="sc">~</span> Q31C21A)) <span class="sc">%&gt;%</span> <span class="co">#&lt;- reported weekly</span></span>
<span id="cb40-48"><a href="#cb40-48" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">Price07 =</span> chcareExp07<span class="sc">/</span>Q31C13) <span class="sc">%&gt;%</span> <span class="co">#&lt;- derive hourly price</span></span>
<span id="cb40-49"><a href="#cb40-49" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">PriceSecond07 =</span> chcareExpSecond07<span class="sc">/</span>Q31C19) <span class="sc">%&gt;%</span> <span class="co">#&lt;- derive hourly price</span></span>
<span id="cb40-50"><a href="#cb40-50" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">Arrange07 =</span> <span class="fu">case_when</span>(Q31C12<span class="sc">==</span><span class="dv">1</span> <span class="sc">|</span> Q31C12<span class="sc">==</span><span class="dv">2</span>  <span class="sc">~</span> <span class="st">"Relative"</span>,</span>
<span id="cb40-51"><a href="#cb40-51" aria-hidden="true" tabindex="-1"></a>                               Q31C12<span class="sc">==</span><span class="dv">3</span> <span class="sc">~</span> <span class="st">"Non Relative"</span>,</span>
<span id="cb40-52"><a href="#cb40-52" aria-hidden="true" tabindex="-1"></a>                               Q31C12<span class="sc">==</span><span class="dv">5</span> <span class="sc">~</span> <span class="st">"Family Center"</span>,</span>
<span id="cb40-53"><a href="#cb40-53" aria-hidden="true" tabindex="-1"></a>                               Q31C12<span class="sc">==</span><span class="dv">7</span> <span class="sc">~</span> <span class="st">"Care Center"</span>,</span>
<span id="cb40-54"><a href="#cb40-54" aria-hidden="true" tabindex="-1"></a>                               Q31C12<span class="sc">==</span><span class="dv">8</span> <span class="sc">~</span> <span class="st">"Before/After School Prog."</span>))<span class="sc">%&gt;%</span></span>
<span id="cb40-55"><a href="#cb40-55" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">ArrangeSecond07 =</span> <span class="fu">case_when</span>(Q31C18<span class="sc">==</span><span class="dv">1</span> <span class="sc">|</span> Q31C18<span class="sc">==</span><span class="dv">2</span>  <span class="sc">~</span> <span class="st">"Relative"</span>,</span>
<span id="cb40-56"><a href="#cb40-56" aria-hidden="true" tabindex="-1"></a>                               Q31C18<span class="sc">==</span><span class="dv">3</span> <span class="sc">~</span> <span class="st">"Non Relative"</span>,</span>
<span id="cb40-57"><a href="#cb40-57" aria-hidden="true" tabindex="-1"></a>                               Q31C18<span class="sc">==</span><span class="dv">5</span> <span class="sc">~</span> <span class="st">"Family Center"</span>,</span>
<span id="cb40-58"><a href="#cb40-58" aria-hidden="true" tabindex="-1"></a>                               Q31C18<span class="sc">==</span><span class="dv">7</span> <span class="sc">~</span> <span class="st">"Care Center"</span>,</span>
<span id="cb40-59"><a href="#cb40-59" aria-hidden="true" tabindex="-1"></a>                               Q31C18<span class="sc">==</span><span class="dv">8</span> <span class="sc">~</span> <span class="st">"Before/After School Prog."</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>One issue is that in 1997, there is a question about whether the arrangement covers other children, and the number. It seems that often it does. It doesn’t appear that the same question is asked in 2002/2007. Currently we are not attempting to normalize by the number of children covered in the arrangement.</p>
<section id="collecting-data-for-younger-children" class="level3">
<h3 class="anchored" data-anchor-id="collecting-data-for-younger-children">Collecting Data for Younger Children</h3>
<p>In addition, for children younger than 5, the data were collected somewhat differently in 1997. These were done as part of retrospective history of child care use. To use these data we first have to clean the history to find current arrangements. Then we put all the data together. The variables are:</p>
<table class="caption-top table">
<thead>
<tr class="header">
<th style="text-align: left;">Vname</th>
<th style="text-align: left;">Variable Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Q1H1Y</td>
<td style="text-align: left;">AGE 1ST CARED BY SOMEONE ELSE (YRS) 97</td>
</tr>
<tr class="even">
<td style="text-align: left;">Q1H1M</td>
<td style="text-align: left;">AGE 1ST CARED BY SOMEONE ELSE (MTHS) 97</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Q1H1A</td>
<td style="text-align: left;">BEFORE/AFTER K’GARTEN 97</td>
</tr>
<tr class="even">
<td style="text-align: left;">Q1H2_1</td>
<td style="text-align: left;">ARRNGMNT #1-REASON 97</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Q1H3_1Y</td>
<td style="text-align: left;">ARRNGMNT #1-AGE START (YRS) 97</td>
</tr>
<tr class="even">
<td style="text-align: left;">Q1H3_1M</td>
<td style="text-align: left;">ARRNGMNT #1-AGE START (MTHS) 97</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Q1H4_1</td>
<td style="text-align: left;">ARRNGMNT #1-TYPE 97</td>
</tr>
<tr class="even">
<td style="text-align: left;">Q1H5_1</td>
<td style="text-align: left;">ARRNGMNT #1-DAYS PER WEEK 97</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Q1H6_1</td>
<td style="text-align: left;">ARRNGMNT #1-HRS PER WEEK 97</td>
</tr>
<tr class="even">
<td style="text-align: left;">Q1H7_1</td>
<td style="text-align: left;">ARRNGMNT #1-COST 97</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Q1H7A_1</td>
<td style="text-align: left;">ARRNGMNT #1- PAYMENT RATE 97</td>
</tr>
<tr class="even">
<td style="text-align: left;">Q1H7B_1</td>
<td style="text-align: left;">ARRNGMNT #1-OTHER CHILDREN 97</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Q1H7C_1</td>
<td style="text-align: left;">ARRNGMNT #1-# OF OTHER CHILDREN 97</td>
</tr>
<tr class="even">
<td style="text-align: left;">Q1H8_1Y</td>
<td style="text-align: left;">ARRNGMNT #1-AGE STOP (YRS) 97</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Q1H8_1M</td>
<td style="text-align: left;">ARRNGMNT #1-AGE STOP (MTHS) 97</td>
</tr>
<tr class="even">
<td style="text-align: left;">Q1H9_1</td>
<td style="text-align: left;">ARRNGMNT #1-REASON STOP 97</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Q1H10_1</td>
<td style="text-align: left;">ARRNGMNT #1-OTHER ARRNGMNTS 97</td>
</tr>
</tbody>
</table>
<div class="cell">
<div class="sourceCode cell-code" id="cb41"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb41-1"><a href="#cb41-1" aria-hidden="true" tabindex="-1"></a><span class="co"># this function calculates the weekly rate given the data</span></span>
<span id="cb41-2"><a href="#cb41-2" aria-hidden="true" tabindex="-1"></a>CalcRate <span class="ot">&lt;-</span> <span class="cf">function</span>(varname,rate,cost,days,hours,Ch) {</span>
<span id="cb41-3"><a href="#cb41-3" aria-hidden="true" tabindex="-1"></a>  I_miss <span class="ot">&lt;-</span> Ch[,cost]<span class="sc">&gt;=</span><span class="dv">99998</span></span>
<span id="cb41-4"><a href="#cb41-4" aria-hidden="true" tabindex="-1"></a>  Ch[I_miss,cost] <span class="ot">&lt;-</span> <span class="cn">NA</span></span>
<span id="cb41-5"><a href="#cb41-5" aria-hidden="true" tabindex="-1"></a>  Ch[,varname] <span class="ot">&lt;-</span> Ch[,cost]</span>
<span id="cb41-6"><a href="#cb41-6" aria-hidden="true" tabindex="-1"></a>  <span class="co"># Case 0: Weekly</span></span>
<span id="cb41-7"><a href="#cb41-7" aria-hidden="true" tabindex="-1"></a>  Ic <span class="ot">=</span> (Ch[,rate]<span class="sc">==</span><span class="dv">3</span>)</span>
<span id="cb41-8"><a href="#cb41-8" aria-hidden="true" tabindex="-1"></a>  Ch[Ic,varname] <span class="ot">=</span> Ch[Ic,cost]</span>
<span id="cb41-9"><a href="#cb41-9" aria-hidden="true" tabindex="-1"></a>  <span class="co"># Case 1: Hourly</span></span>
<span id="cb41-10"><a href="#cb41-10" aria-hidden="true" tabindex="-1"></a>  Ic <span class="ot">=</span> (Ch[,rate]<span class="sc">==</span><span class="dv">1</span>)</span>
<span id="cb41-11"><a href="#cb41-11" aria-hidden="true" tabindex="-1"></a>  Ch[Ic,varname] <span class="ot">=</span> Ch[Ic,cost]<span class="sc">*</span>Ch[Ic,hours]</span>
<span id="cb41-12"><a href="#cb41-12" aria-hidden="true" tabindex="-1"></a>  <span class="co"># Case 2: Daily</span></span>
<span id="cb41-13"><a href="#cb41-13" aria-hidden="true" tabindex="-1"></a>  Ic <span class="ot">=</span> (Ch[,rate]<span class="sc">==</span><span class="dv">2</span>)</span>
<span id="cb41-14"><a href="#cb41-14" aria-hidden="true" tabindex="-1"></a>  Ch[Ic,varname] <span class="ot">=</span> Ch[Ic,cost]<span class="sc">*</span>Ch[Ic,days]</span>
<span id="cb41-15"><a href="#cb41-15" aria-hidden="true" tabindex="-1"></a>  <span class="co"># Case 4: Fortnightly</span></span>
<span id="cb41-16"><a href="#cb41-16" aria-hidden="true" tabindex="-1"></a>  Ic <span class="ot">=</span> (Ch[,rate]<span class="sc">==</span><span class="dv">4</span>)</span>
<span id="cb41-17"><a href="#cb41-17" aria-hidden="true" tabindex="-1"></a>  Ch[Ic,varname] <span class="ot">=</span> Ch[Ic,cost]<span class="sc">/</span><span class="dv">2</span></span>
<span id="cb41-18"><a href="#cb41-18" aria-hidden="true" tabindex="-1"></a>  <span class="co"># Case 5: Monthly</span></span>
<span id="cb41-19"><a href="#cb41-19" aria-hidden="true" tabindex="-1"></a>  Ic <span class="ot">=</span> (Ch[,rate]<span class="sc">==</span><span class="dv">5</span>)</span>
<span id="cb41-20"><a href="#cb41-20" aria-hidden="true" tabindex="-1"></a>  Ch[Ic,varname] <span class="ot">=</span> Ch[Ic,cost]<span class="sc">/</span><span class="dv">4</span></span>
<span id="cb41-21"><a href="#cb41-21" aria-hidden="true" tabindex="-1"></a>  <span class="co"># Case 6: Annual</span></span>
<span id="cb41-22"><a href="#cb41-22" aria-hidden="true" tabindex="-1"></a>  Ic <span class="ot">=</span> (Ch[,rate]<span class="sc">==</span><span class="dv">6</span>)</span>
<span id="cb41-23"><a href="#cb41-23" aria-hidden="true" tabindex="-1"></a>  Ch[Ic,varname] <span class="ot">=</span> Ch[Ic,cost]<span class="sc">/</span><span class="dv">52</span></span>
<span id="cb41-24"><a href="#cb41-24" aria-hidden="true" tabindex="-1"></a>  Ch</span>
<span id="cb41-25"><a href="#cb41-25" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb41-26"><a href="#cb41-26" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb41-27"><a href="#cb41-27" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb41-28"><a href="#cb41-28" aria-hidden="true" tabindex="-1"></a>ch_hist <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/cds/childcare/Childcare_history.xlsx"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb41-29"><a href="#cb41-29" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">KID =</span> ER30001<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> ER30002)</span>
<span id="cb41-30"><a href="#cb41-30" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb41-31"><a href="#cb41-31" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb41-32"><a href="#cb41-32" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (i <span class="cf">in</span> <span class="fu">seq</span>(<span class="dv">1</span>,<span class="dv">8</span>)) {</span>
<span id="cb41-33"><a href="#cb41-33" aria-hidden="true" tabindex="-1"></a>  vname <span class="ot">=</span> <span class="fu">paste</span>(<span class="st">"exp97_"</span>,i,<span class="at">sep=</span><span class="st">""</span>)</span>
<span id="cb41-34"><a href="#cb41-34" aria-hidden="true" tabindex="-1"></a>  rate <span class="ot">=</span> <span class="fu">paste</span>(<span class="st">"Q1H7A_"</span>,i,<span class="at">sep=</span><span class="st">""</span>)</span>
<span id="cb41-35"><a href="#cb41-35" aria-hidden="true" tabindex="-1"></a>  cost <span class="ot">=</span> <span class="fu">paste</span>(<span class="st">"Q1H7_"</span>,i,<span class="at">sep=</span><span class="st">""</span>)</span>
<span id="cb41-36"><a href="#cb41-36" aria-hidden="true" tabindex="-1"></a>  days <span class="ot">=</span> <span class="fu">paste</span>(<span class="st">"Q1H5_"</span>,i,<span class="at">sep=</span><span class="st">""</span>)</span>
<span id="cb41-37"><a href="#cb41-37" aria-hidden="true" tabindex="-1"></a>  hours <span class="ot">=</span> <span class="fu">paste</span>(<span class="st">"Q1H6_"</span>,i,<span class="at">sep=</span><span class="st">""</span>)</span>
<span id="cb41-38"><a href="#cb41-38" aria-hidden="true" tabindex="-1"></a>  <span class="co"># replace missing hours with NA:</span></span>
<span id="cb41-39"><a href="#cb41-39" aria-hidden="true" tabindex="-1"></a>  ch_hist[ch_hist[,hours]<span class="sc">==</span><span class="dv">998</span><span class="sc">|</span>ch_hist[,hours]<span class="sc">==</span><span class="dv">999</span>,hours]<span class="ot">=</span> <span class="cn">NA_real_</span></span>
<span id="cb41-40"><a href="#cb41-40" aria-hidden="true" tabindex="-1"></a> <span class="co">#ch_hist[,hours] = na_if(ch_hist[,hours],998)</span></span>
<span id="cb41-41"><a href="#cb41-41" aria-hidden="true" tabindex="-1"></a> <span class="co">#ch_hist[,hours] = na_if(ch_hist[,hours],999)</span></span>
<span id="cb41-42"><a href="#cb41-42" aria-hidden="true" tabindex="-1"></a>  ch_hist <span class="ot">&lt;-</span> <span class="fu">CalcRate</span>(vname,rate,cost,days,hours,ch_hist)</span>
<span id="cb41-43"><a href="#cb41-43" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb41-44"><a href="#cb41-44" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb41-45"><a href="#cb41-45" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb41-46"><a href="#cb41-46" aria-hidden="true" tabindex="-1"></a>ch_hist<span class="sc">$</span>Arrange <span class="ot">&lt;-</span> <span class="sc">-</span><span class="dv">1</span></span>
<span id="cb41-47"><a href="#cb41-47" aria-hidden="true" tabindex="-1"></a>ch_hist<span class="sc">$</span>Freq <span class="ot">&lt;-</span> <span class="dv">0</span></span>
<span id="cb41-48"><a href="#cb41-48" aria-hidden="true" tabindex="-1"></a>ch_hist<span class="sc">$</span>Exp97 <span class="ot">&lt;-</span> <span class="sc">-</span><span class="dv">1</span></span>
<span id="cb41-49"><a href="#cb41-49" aria-hidden="true" tabindex="-1"></a>ch_hist<span class="sc">$</span>Hours97 <span class="ot">&lt;-</span> <span class="sc">-</span><span class="dv">1</span></span>
<span id="cb41-50"><a href="#cb41-50" aria-hidden="true" tabindex="-1"></a>ch_hist<span class="sc">$</span>Exp97Tot <span class="ot">&lt;-</span> <span class="dv">0</span></span>
<span id="cb41-51"><a href="#cb41-51" aria-hidden="true" tabindex="-1"></a>ch_hist<span class="sc">$</span>Hours97Tot <span class="ot">&lt;-</span> <span class="dv">0</span></span>
<span id="cb41-52"><a href="#cb41-52" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb41-53"><a href="#cb41-53" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (i <span class="cf">in</span> <span class="fu">seq</span>(<span class="dv">1</span>,<span class="fu">nrow</span>(ch_hist))) {</span>
<span id="cb41-54"><a href="#cb41-54" aria-hidden="true" tabindex="-1"></a>  <span class="cf">if</span> (ch_hist[i,<span class="st">"Q1H1Y"</span>]<span class="sc">==</span><span class="dv">0</span>) {</span>
<span id="cb41-55"><a href="#cb41-55" aria-hidden="true" tabindex="-1"></a>    ch_hist[i,<span class="st">"Arrange"</span>] <span class="ot">=</span> <span class="dv">0</span></span>
<span id="cb41-56"><a href="#cb41-56" aria-hidden="true" tabindex="-1"></a>  }</span>
<span id="cb41-57"><a href="#cb41-57" aria-hidden="true" tabindex="-1"></a>  <span class="cf">else</span> {</span>
<span id="cb41-58"><a href="#cb41-58" aria-hidden="true" tabindex="-1"></a>    <span class="cf">for</span> (j <span class="cf">in</span> <span class="fu">seq</span>(<span class="dv">1</span>,<span class="dv">8</span>)) {</span>
<span id="cb41-59"><a href="#cb41-59" aria-hidden="true" tabindex="-1"></a>      <span class="cf">if</span> (ch_hist[i,<span class="fu">paste</span>(<span class="st">"Q1H8_"</span>,j,<span class="st">"Y"</span>,<span class="at">sep=</span><span class="st">""</span>)]<span class="sc">==</span><span class="dv">96</span>) {</span>
<span id="cb41-60"><a href="#cb41-60" aria-hidden="true" tabindex="-1"></a>        freq_var <span class="ot">=</span> <span class="fu">paste</span>(<span class="st">"Q1H5_"</span>,j,<span class="at">sep=</span><span class="st">""</span>)</span>
<span id="cb41-61"><a href="#cb41-61" aria-hidden="true" tabindex="-1"></a>        ch_hist[i,<span class="st">"Exp97Tot"</span>] <span class="ot">=</span> ch_hist[i,<span class="st">"Exp97Tot"</span>] <span class="sc">+</span> ch_hist[i,<span class="fu">paste</span>(<span class="st">"exp97_"</span>,j,<span class="at">sep=</span><span class="st">""</span>)]</span>
<span id="cb41-62"><a href="#cb41-62" aria-hidden="true" tabindex="-1"></a>        ch_hist[i,<span class="st">"Hours97Tot"</span>] <span class="ot">=</span> ch_hist[i,<span class="st">"Hours97Tot"</span>] <span class="sc">+</span> ch_hist[i,<span class="fu">paste</span>(<span class="st">"Q1H6_"</span>,j,<span class="at">sep=</span><span class="st">""</span>)]</span>
<span id="cb41-63"><a href="#cb41-63" aria-hidden="true" tabindex="-1"></a>        days_per_week <span class="ot">=</span> ch_hist[i,freq_var]</span>
<span id="cb41-64"><a href="#cb41-64" aria-hidden="true" tabindex="-1"></a>        <span class="cf">if</span> (days_per_week<span class="sc">&gt;</span>ch_hist[i,<span class="st">"Freq"</span>] <span class="sc">&amp;</span> days_per_week<span class="sc">&lt;</span><span class="dv">8</span>) {</span>
<span id="cb41-65"><a href="#cb41-65" aria-hidden="true" tabindex="-1"></a>          ch_hist[i,<span class="st">"Arrange"</span>] <span class="ot">=</span> ch_hist[i,<span class="fu">paste</span>(<span class="st">"Q1H4_"</span>,j,<span class="at">sep=</span><span class="st">""</span>)]</span>
<span id="cb41-66"><a href="#cb41-66" aria-hidden="true" tabindex="-1"></a>          ch_hist[i,<span class="st">"Freq"</span>] <span class="ot">=</span> ch_hist[i,freq_var]</span>
<span id="cb41-67"><a href="#cb41-67" aria-hidden="true" tabindex="-1"></a>          ch_hist[i,<span class="st">"Exp97"</span>] <span class="ot">=</span> ch_hist[i,<span class="fu">paste</span>(<span class="st">"exp97_"</span>,j,<span class="at">sep=</span><span class="st">""</span>)]</span>
<span id="cb41-68"><a href="#cb41-68" aria-hidden="true" tabindex="-1"></a>          ch_hist[i,<span class="st">"Hours97"</span>] <span class="ot">=</span> ch_hist[i,<span class="fu">paste</span>(<span class="st">"Q1H6_"</span>,j,<span class="at">sep=</span><span class="st">""</span>)]</span>
<span id="cb41-69"><a href="#cb41-69" aria-hidden="true" tabindex="-1"></a>        }</span>
<span id="cb41-70"><a href="#cb41-70" aria-hidden="true" tabindex="-1"></a>      }</span>
<span id="cb41-71"><a href="#cb41-71" aria-hidden="true" tabindex="-1"></a>    }</span>
<span id="cb41-72"><a href="#cb41-72" aria-hidden="true" tabindex="-1"></a>  }</span>
<span id="cb41-73"><a href="#cb41-73" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb41-74"><a href="#cb41-74" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb41-75"><a href="#cb41-75" aria-hidden="true" tabindex="-1"></a><span class="co"># now code up arrangements:</span></span>
<span id="cb41-76"><a href="#cb41-76" aria-hidden="true" tabindex="-1"></a><span class="co"># - Childcare arrangements</span></span>
<span id="cb41-77"><a href="#cb41-77" aria-hidden="true" tabindex="-1"></a>ch_hist<span class="sc">$</span>Arrange97 <span class="ot">&lt;-</span> <span class="cn">NA</span></span>
<span id="cb41-78"><a href="#cb41-78" aria-hidden="true" tabindex="-1"></a>I1 <span class="ot">&lt;-</span> ch_hist<span class="sc">$</span>Arrange<span class="sc">==</span><span class="dv">0</span></span>
<span id="cb41-79"><a href="#cb41-79" aria-hidden="true" tabindex="-1"></a>ch_hist<span class="sc">$</span>Arrange97[I1] <span class="ot">&lt;-</span> <span class="st">"Never Cared for By Other"</span></span>
<span id="cb41-80"><a href="#cb41-80" aria-hidden="true" tabindex="-1"></a>I1 <span class="ot">&lt;-</span> <span class="fu">is.na</span>(ch_hist<span class="sc">$</span>Arrange)</span>
<span id="cb41-81"><a href="#cb41-81" aria-hidden="true" tabindex="-1"></a>ch_hist<span class="sc">$</span>Arrange97[I1] <span class="ot">&lt;-</span> <span class="st">"No Detectable Arrangement"</span></span>
<span id="cb41-82"><a href="#cb41-82" aria-hidden="true" tabindex="-1"></a>I1 <span class="ot">&lt;-</span> ch_hist<span class="sc">$</span>Arrange<span class="sc">==</span><span class="dv">1</span> <span class="sc">|</span> ch_hist<span class="sc">$</span>Arrange<span class="sc">==</span><span class="dv">3</span></span>
<span id="cb41-83"><a href="#cb41-83" aria-hidden="true" tabindex="-1"></a>ch_hist<span class="sc">$</span>Arrange97[I1] <span class="ot">&lt;-</span> <span class="st">"Relative"</span></span>
<span id="cb41-84"><a href="#cb41-84" aria-hidden="true" tabindex="-1"></a>I1 <span class="ot">&lt;-</span> ch_hist<span class="sc">$</span>Arrange<span class="sc">==</span><span class="dv">2</span> <span class="sc">|</span> ch_hist<span class="sc">$</span>Arrange<span class="sc">==</span><span class="dv">4</span></span>
<span id="cb41-85"><a href="#cb41-85" aria-hidden="true" tabindex="-1"></a>ch_hist<span class="sc">$</span>Arrange97[I1] <span class="ot">&lt;-</span> <span class="st">"Non Relative"</span></span>
<span id="cb41-86"><a href="#cb41-86" aria-hidden="true" tabindex="-1"></a>I1 <span class="ot">&lt;-</span> ch_hist<span class="sc">$</span>Arrange<span class="sc">==</span><span class="dv">5</span></span>
<span id="cb41-87"><a href="#cb41-87" aria-hidden="true" tabindex="-1"></a>ch_hist<span class="sc">$</span>Arrange97[I1] <span class="ot">&lt;-</span> <span class="st">"Head Start"</span></span>
<span id="cb41-88"><a href="#cb41-88" aria-hidden="true" tabindex="-1"></a>I1 <span class="ot">&lt;-</span> ch_hist<span class="sc">$</span>Arrange<span class="sc">==</span><span class="dv">6</span></span>
<span id="cb41-89"><a href="#cb41-89" aria-hidden="true" tabindex="-1"></a>ch_hist<span class="sc">$</span>Arrange97[I1] <span class="ot">&lt;-</span> <span class="st">"Care Center"</span></span>
<span id="cb41-90"><a href="#cb41-90" aria-hidden="true" tabindex="-1"></a>I1 <span class="ot">&lt;-</span> ch_hist<span class="sc">$</span>Arrange<span class="sc">==</span><span class="dv">7</span></span>
<span id="cb41-91"><a href="#cb41-91" aria-hidden="true" tabindex="-1"></a>ch_hist<span class="sc">$</span>Arrange97[I1] <span class="ot">&lt;-</span> <span class="st">"Before/After School Prog."</span></span>
<span id="cb41-92"><a href="#cb41-92" aria-hidden="true" tabindex="-1"></a>I1 <span class="ot">&lt;-</span> ch_hist<span class="sc">$</span>Arrange<span class="sc">==</span><span class="dv">8</span></span>
<span id="cb41-93"><a href="#cb41-93" aria-hidden="true" tabindex="-1"></a>ch_hist<span class="sc">$</span>Arrange97[I1] <span class="ot">&lt;-</span> <span class="st">"Self Care"</span></span>
<span id="cb41-94"><a href="#cb41-94" aria-hidden="true" tabindex="-1"></a>I1 <span class="ot">&lt;-</span> ch_hist<span class="sc">$</span>Arrange<span class="sc">&gt;=</span><span class="dv">97</span></span>
<span id="cb41-95"><a href="#cb41-95" aria-hidden="true" tabindex="-1"></a>ch_hist<span class="sc">$</span>Arrange97[I1] <span class="ot">&lt;-</span> <span class="st">"Unkown Type"</span></span>
<span id="cb41-96"><a href="#cb41-96" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb41-97"><a href="#cb41-97" aria-hidden="true" tabindex="-1"></a><span class="co"># code a more basic breakdown:</span></span>
<span id="cb41-98"><a href="#cb41-98" aria-hidden="true" tabindex="-1"></a>ch_hist<span class="sc">$</span>CaretypeBroad <span class="ot">&lt;-</span> <span class="st">"External"</span></span>
<span id="cb41-99"><a href="#cb41-99" aria-hidden="true" tabindex="-1"></a>ch_hist<span class="sc">$</span>CaretypeBroad[ch_hist<span class="sc">$</span>Arrange<span class="sc">==</span><span class="dv">0</span>] <span class="ot">&lt;-</span> <span class="st">"Never Care for by Other"</span></span>
<span id="cb41-100"><a href="#cb41-100" aria-hidden="true" tabindex="-1"></a>ch_hist<span class="sc">$</span>CaretypeBroad[<span class="fu">is.na</span>(ch_hist<span class="sc">$</span>Arrange)] <span class="ot">&lt;-</span> <span class="st">"No Current Detectable"</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Next we merge these data with the rest to create a panel.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb42"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb42-1"><a href="#cb42-1" aria-hidden="true" tabindex="-1"></a>C97 <span class="ot">&lt;-</span> Ch97[,<span class="fu">c</span>(<span class="st">"KID"</span>,<span class="st">"chcareExp97"</span>,<span class="st">"Arrange97"</span>,<span class="st">"Price97"</span>,<span class="st">"chcareExpSecond97"</span>,<span class="st">"ArrangeSecond97"</span>,<span class="st">"PriceSecond97"</span>)]</span>
<span id="cb42-2"><a href="#cb42-2" aria-hidden="true" tabindex="-1"></a>C97<span class="sc">$</span>year <span class="ot">&lt;-</span> <span class="dv">1997</span></span>
<span id="cb42-3"><a href="#cb42-3" aria-hidden="true" tabindex="-1"></a>C97 <span class="ot">&lt;-</span> <span class="fu">rename</span>(C97,<span class="at">chcare =</span> chcareExp97,<span class="at">Arrange =</span> Arrange97, <span class="at">Price =</span> Price97,</span>
<span id="cb42-4"><a href="#cb42-4" aria-hidden="true" tabindex="-1"></a>              <span class="at">chcare_second=</span>chcareExpSecond97, <span class="at">ArrangeSecond =</span> ArrangeSecond97, <span class="at">PriceSecond =</span> PriceSecond97)</span>
<span id="cb42-5"><a href="#cb42-5" aria-hidden="true" tabindex="-1"></a><span class="co"># now load preK data and merge, replacing the child care value with this value when available</span></span>
<span id="cb42-6"><a href="#cb42-6" aria-hidden="true" tabindex="-1"></a>C97 <span class="ot">&lt;-</span> ch_hist <span class="sc">%&gt;%</span></span>
<span id="cb42-7"><a href="#cb42-7" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(KID,Exp97Tot) <span class="sc">%&gt;%</span></span>
<span id="cb42-8"><a href="#cb42-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">Exp97Tot =</span> <span class="fu">na_if</span>(Exp97Tot,<span class="dv">9998</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb42-9"><a href="#cb42-9" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(C97) <span class="sc">%&gt;%</span></span>
<span id="cb42-10"><a href="#cb42-10" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">chcare =</span> <span class="fu">case_when</span>(Exp97Tot<span class="sc">&gt;</span><span class="dv">0</span> <span class="sc">~</span> Exp97Tot,<span class="cn">TRUE</span> <span class="sc">~</span> chcare)) <span class="sc">%&gt;%</span></span>
<span id="cb42-11"><a href="#cb42-11" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(<span class="sc">-</span>Exp97Tot)</span>
<span id="cb42-12"><a href="#cb42-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb42-13"><a href="#cb42-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb42-14"><a href="#cb42-14" aria-hidden="true" tabindex="-1"></a>C02 <span class="ot">&lt;-</span> Ch02[,<span class="fu">c</span>(<span class="st">"KID"</span>,<span class="st">"chcareExp02"</span>,<span class="st">"Arrange02"</span>,<span class="st">"Price02"</span>,<span class="st">"chcareExpSecond02"</span>,<span class="st">"ArrangeSecond02"</span>,<span class="st">"PriceSecond02"</span>)]</span>
<span id="cb42-15"><a href="#cb42-15" aria-hidden="true" tabindex="-1"></a>C02<span class="sc">$</span>year <span class="ot">&lt;-</span> <span class="dv">2002</span></span>
<span id="cb42-16"><a href="#cb42-16" aria-hidden="true" tabindex="-1"></a>C02 <span class="ot">&lt;-</span> <span class="fu">rename</span>(C02,<span class="at">chcare =</span> chcareExp02,<span class="at">Arrange =</span> Arrange02, <span class="at">Price =</span> Price02,</span>
<span id="cb42-17"><a href="#cb42-17" aria-hidden="true" tabindex="-1"></a>              <span class="at">chcare_second=</span>chcareExpSecond02, <span class="at">ArrangeSecond =</span> ArrangeSecond02, <span class="at">PriceSecond =</span> PriceSecond02)</span>
<span id="cb42-18"><a href="#cb42-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb42-19"><a href="#cb42-19" aria-hidden="true" tabindex="-1"></a>C07 <span class="ot">&lt;-</span> Ch07[,<span class="fu">c</span>(<span class="st">"KID"</span>,<span class="st">"chcareExp07"</span>,<span class="st">"Arrange07"</span>,<span class="st">"Price07"</span>,<span class="st">"chcareExpSecond07"</span>,<span class="st">"ArrangeSecond07"</span>,<span class="st">"PriceSecond07"</span>)]</span>
<span id="cb42-20"><a href="#cb42-20" aria-hidden="true" tabindex="-1"></a>C07<span class="sc">$</span>year <span class="ot">&lt;-</span> <span class="dv">2007</span></span>
<span id="cb42-21"><a href="#cb42-21" aria-hidden="true" tabindex="-1"></a>C07 <span class="ot">&lt;-</span> <span class="fu">rename</span>(C07,<span class="at">chcare =</span> chcareExp07,<span class="at">Arrange =</span> Arrange07, <span class="at">Price =</span> Price07,</span>
<span id="cb42-22"><a href="#cb42-22" aria-hidden="true" tabindex="-1"></a>              <span class="at">chcare_second=</span>chcareExpSecond07, <span class="at">ArrangeSecond =</span> ArrangeSecond07, <span class="at">PriceSecond =</span> PriceSecond07)</span>
<span id="cb42-23"><a href="#cb42-23" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb42-24"><a href="#cb42-24" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb42-25"><a href="#cb42-25" aria-hidden="true" tabindex="-1"></a>cds_childcare <span class="ot">&lt;-</span> <span class="fu">rbind</span>(C97,C02,C07) </span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
</section>
<section id="age-by-month" class="level2">
<h2 class="anchored" data-anchor-id="age-by-month">Age by Month</h2>
<p>Construct the age in months for CDS years</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb43"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb43-1"><a href="#cb43-1" aria-hidden="true" tabindex="-1"></a>age_month <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/cds/staff-child-ratios/age_month.xlsx"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb43-2"><a href="#cb43-2" aria-hidden="true" tabindex="-1"></a>      <span class="fu">mutate</span>(<span class="at">KID =</span> ER30001<span class="sc">*</span><span class="dv">1000</span> <span class="sc">+</span> ER30002) <span class="sc">%&gt;%</span></span>
<span id="cb43-3"><a href="#cb43-3" aria-hidden="true" tabindex="-1"></a>      <span class="fu">rename</span>(<span class="at">age_month_1997=</span>AGEATPCG)<span class="sc">%&gt;%</span></span>
<span id="cb43-4"><a href="#cb43-4" aria-hidden="true" tabindex="-1"></a>      <span class="co">#replace full birthdate unknown values to missing</span></span>
<span id="cb43-5"><a href="#cb43-5" aria-hidden="true" tabindex="-1"></a>      <span class="fu">mutate</span>(<span class="at">age_month_1997=</span><span class="fu">na_if</span>(age_month_1997,<span class="fl">999.9</span>))<span class="sc">%&gt;%</span></span>
<span id="cb43-6"><a href="#cb43-6" aria-hidden="true" tabindex="-1"></a>      <span class="fu">mutate</span>(<span class="at">age_month_1997=</span><span class="fu">floor</span>(age_month_1997))<span class="sc">%&gt;%</span></span>
<span id="cb43-7"><a href="#cb43-7" aria-hidden="true" tabindex="-1"></a>      <span class="fu">mutate</span>(<span class="at">month_1997 =</span>PCGIWYR  <span class="sc">*</span> <span class="dv">12</span> <span class="sc">+</span> PCGIWMON )<span class="sc">%&gt;%</span></span>
<span id="cb43-8"><a href="#cb43-8" aria-hidden="true" tabindex="-1"></a>      <span class="fu">mutate</span>(<span class="at">month_2002 =</span> Q21IWYR <span class="sc">*</span> <span class="dv">12</span> <span class="sc">+</span> Q21IWMTH )<span class="sc">%&gt;%</span></span>
<span id="cb43-9"><a href="#cb43-9" aria-hidden="true" tabindex="-1"></a>      <span class="fu">mutate</span>(<span class="at">month_2007 =</span>  Q31IWYR <span class="sc">*</span> <span class="dv">12</span> <span class="sc">+</span> Q31IWMTH)</span>
<span id="cb43-10"><a href="#cb43-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb43-11"><a href="#cb43-11" aria-hidden="true" tabindex="-1"></a><span class="co">#Compute age in months at 1997 interview</span></span>
<span id="cb43-12"><a href="#cb43-12" aria-hidden="true" tabindex="-1"></a>age_month_1997 <span class="ot">&lt;-</span> age_month <span class="sc">%&gt;%</span></span>
<span id="cb43-13"><a href="#cb43-13" aria-hidden="true" tabindex="-1"></a>      <span class="fu">select</span>(KID, age_month_1997)<span class="sc">%&gt;%</span></span>
<span id="cb43-14"><a href="#cb43-14" aria-hidden="true" tabindex="-1"></a>      <span class="fu">rename</span>(<span class="at">age_month=</span>age_month_1997)<span class="sc">%&gt;%</span></span>
<span id="cb43-15"><a href="#cb43-15" aria-hidden="true" tabindex="-1"></a>      <span class="fu">mutate</span>(<span class="at">year=</span><span class="dv">1997</span>)</span>
<span id="cb43-16"><a href="#cb43-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb43-17"><a href="#cb43-17" aria-hidden="true" tabindex="-1"></a><span class="co">#Compute age in months at 2002 interview using age in months in 1997 </span></span>
<span id="cb43-18"><a href="#cb43-18" aria-hidden="true" tabindex="-1"></a><span class="co">#and time difference between 2002 and 1997 interviews</span></span>
<span id="cb43-19"><a href="#cb43-19" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb43-20"><a href="#cb43-20" aria-hidden="true" tabindex="-1"></a>age_month_2002 <span class="ot">&lt;-</span>  age_month <span class="sc">%&gt;%</span></span>
<span id="cb43-21"><a href="#cb43-21" aria-hidden="true" tabindex="-1"></a>      <span class="fu">select</span>(KID, age_month_1997, month_2002, month_1997)<span class="sc">%&gt;%</span></span>
<span id="cb43-22"><a href="#cb43-22" aria-hidden="true" tabindex="-1"></a>      <span class="fu">mutate</span>(<span class="at">age_month=</span>age_month_1997<span class="sc">+</span>month_2002<span class="sc">-</span>month_1997, <span class="at">year=</span><span class="dv">2002</span>)<span class="sc">%&gt;%</span></span>
<span id="cb43-23"><a href="#cb43-23" aria-hidden="true" tabindex="-1"></a>      <span class="fu">select</span>(<span class="sc">-</span>month_2002, <span class="sc">-</span>month_1997, <span class="sc">-</span>age_month_1997)</span>
<span id="cb43-24"><a href="#cb43-24" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb43-25"><a href="#cb43-25" aria-hidden="true" tabindex="-1"></a><span class="co">#Compute age in months at 2007 interview using age in months in 1997 </span></span>
<span id="cb43-26"><a href="#cb43-26" aria-hidden="true" tabindex="-1"></a><span class="co">#and time difference between 2007 and 1997 interviews</span></span>
<span id="cb43-27"><a href="#cb43-27" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb43-28"><a href="#cb43-28" aria-hidden="true" tabindex="-1"></a>age_month_2007 <span class="ot">&lt;-</span>  age_month <span class="sc">%&gt;%</span></span>
<span id="cb43-29"><a href="#cb43-29" aria-hidden="true" tabindex="-1"></a>      <span class="fu">select</span>(KID, age_month_1997, month_2007, month_1997)<span class="sc">%&gt;%</span></span>
<span id="cb43-30"><a href="#cb43-30" aria-hidden="true" tabindex="-1"></a>      <span class="fu">mutate</span>(<span class="at">age_month=</span>age_month_1997<span class="sc">+</span>month_2007<span class="sc">-</span>month_1997, <span class="at">year=</span><span class="dv">2007</span>)<span class="sc">%&gt;%</span></span>
<span id="cb43-31"><a href="#cb43-31" aria-hidden="true" tabindex="-1"></a>      <span class="fu">select</span>(<span class="sc">-</span>month_2007, <span class="sc">-</span>month_1997, <span class="sc">-</span>age_month_1997)</span>
<span id="cb43-32"><a href="#cb43-32" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb43-33"><a href="#cb43-33" aria-hidden="true" tabindex="-1"></a><span class="co">#Make a panel for age in months 1997, 2002, and 2007</span></span>
<span id="cb43-34"><a href="#cb43-34" aria-hidden="true" tabindex="-1"></a>age_month <span class="ot">&lt;-</span> <span class="fu">rbind</span>(age_month_1997,age_month_2002, age_month_2007)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="staff-child-ratios" class="level2">
<h2 class="anchored" data-anchor-id="staff-child-ratios">Staff-child ratios</h2>
<p>Map the age in months of each child to a staff to child ratio</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb44"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb44-1"><a href="#cb44-1" aria-hidden="true" tabindex="-1"></a>staff_ratio <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/cds/staff-child-ratios/Ratios_Center_Based_2002.xlsx"</span>)</span>
<span id="cb44-2"><a href="#cb44-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-3"><a href="#cb44-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-4"><a href="#cb44-4" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-5"><a href="#cb44-5" aria-hidden="true" tabindex="-1"></a><span class="co">#Age 0-8 months</span></span>
<span id="cb44-6"><a href="#cb44-6" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-7"><a href="#cb44-7" aria-hidden="true" tabindex="-1"></a>staff_ratio_0_8 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-8"><a href="#cb44-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_0_8)<span class="sc">%&gt;%</span></span>
<span id="cb44-9"><a href="#cb44-9" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">0</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-10"><a href="#cb44-10" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_0_8)</span>
<span id="cb44-11"><a href="#cb44-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-12"><a href="#cb44-12" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-13"><a href="#cb44-13" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span><span class="dv">8</span>) {</span>
<span id="cb44-14"><a href="#cb44-14" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-15"><a href="#cb44-15" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_0_8)<span class="sc">%&gt;%</span></span>
<span id="cb44-16"><a href="#cb44-16" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-17"><a href="#cb44-17" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_0_8)</span>
<span id="cb44-18"><a href="#cb44-18" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb44-19"><a href="#cb44-19" aria-hidden="true" tabindex="-1"></a>  staff_ratio_0_8<span class="ot">=</span> <span class="fu">rbind</span>(staff_ratio_0_8,temp)</span>
<span id="cb44-20"><a href="#cb44-20" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-21"><a href="#cb44-21" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-22"><a href="#cb44-22" aria-hidden="true" tabindex="-1"></a><span class="co">#Second version with cutoffs 6 months later</span></span>
<span id="cb44-23"><a href="#cb44-23" aria-hidden="true" tabindex="-1"></a>staff_ratio_0_14 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-24"><a href="#cb44-24" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_0_8)<span class="sc">%&gt;%</span></span>
<span id="cb44-25"><a href="#cb44-25" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">0</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-26"><a href="#cb44-26" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_0_8)</span>
<span id="cb44-27"><a href="#cb44-27" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-28"><a href="#cb44-28" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-29"><a href="#cb44-29" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span><span class="dv">14</span>) {</span>
<span id="cb44-30"><a href="#cb44-30" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-31"><a href="#cb44-31" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_0_8)<span class="sc">%&gt;%</span></span>
<span id="cb44-32"><a href="#cb44-32" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-33"><a href="#cb44-33" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_0_8)</span>
<span id="cb44-34"><a href="#cb44-34" aria-hidden="true" tabindex="-1"></a>  staff_ratio_0_14<span class="ot">=</span> <span class="fu">rbind</span>(staff_ratio_0_14,temp)</span>
<span id="cb44-35"><a href="#cb44-35" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-36"><a href="#cb44-36" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-37"><a href="#cb44-37" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-38"><a href="#cb44-38" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-39"><a href="#cb44-39" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-40"><a href="#cb44-40" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-41"><a href="#cb44-41" aria-hidden="true" tabindex="-1"></a><span class="co">#Age 9-17 months</span></span>
<span id="cb44-42"><a href="#cb44-42" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-43"><a href="#cb44-43" aria-hidden="true" tabindex="-1"></a>staff_ratio_9_17 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-44"><a href="#cb44-44" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_9_17)<span class="sc">%&gt;%</span></span>
<span id="cb44-45"><a href="#cb44-45" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">9</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-46"><a href="#cb44-46" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_9_17)</span>
<span id="cb44-47"><a href="#cb44-47" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-48"><a href="#cb44-48" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-49"><a href="#cb44-49" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">10</span><span class="sc">:</span><span class="dv">17</span>) {</span>
<span id="cb44-50"><a href="#cb44-50" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-51"><a href="#cb44-51" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_9_17)<span class="sc">%&gt;%</span></span>
<span id="cb44-52"><a href="#cb44-52" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-53"><a href="#cb44-53" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_9_17)</span>
<span id="cb44-54"><a href="#cb44-54" aria-hidden="true" tabindex="-1"></a>  staff_ratio_9_17<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_9_17,temp)</span>
<span id="cb44-55"><a href="#cb44-55" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-56"><a href="#cb44-56" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-57"><a href="#cb44-57" aria-hidden="true" tabindex="-1"></a><span class="co">#Second version with cutoffs 6 months later</span></span>
<span id="cb44-58"><a href="#cb44-58" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-59"><a href="#cb44-59" aria-hidden="true" tabindex="-1"></a>staff_ratio_15_23 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-60"><a href="#cb44-60" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_9_17)<span class="sc">%&gt;%</span></span>
<span id="cb44-61"><a href="#cb44-61" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">15</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-62"><a href="#cb44-62" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_9_17)</span>
<span id="cb44-63"><a href="#cb44-63" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-64"><a href="#cb44-64" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-65"><a href="#cb44-65" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">16</span><span class="sc">:</span><span class="dv">23</span>) {</span>
<span id="cb44-66"><a href="#cb44-66" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-67"><a href="#cb44-67" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_9_17)<span class="sc">%&gt;%</span></span>
<span id="cb44-68"><a href="#cb44-68" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-69"><a href="#cb44-69" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_9_17)</span>
<span id="cb44-70"><a href="#cb44-70" aria-hidden="true" tabindex="-1"></a>  staff_ratio_15_23<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_15_23,temp)</span>
<span id="cb44-71"><a href="#cb44-71" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-72"><a href="#cb44-72" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-73"><a href="#cb44-73" aria-hidden="true" tabindex="-1"></a><span class="co">#Age 18-26</span></span>
<span id="cb44-74"><a href="#cb44-74" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-75"><a href="#cb44-75" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-76"><a href="#cb44-76" aria-hidden="true" tabindex="-1"></a>staff_ratio_18_26 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-77"><a href="#cb44-77" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_18_26)<span class="sc">%&gt;%</span></span>
<span id="cb44-78"><a href="#cb44-78" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">18</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-79"><a href="#cb44-79" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_18_26)</span>
<span id="cb44-80"><a href="#cb44-80" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-81"><a href="#cb44-81" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-82"><a href="#cb44-82" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">19</span><span class="sc">:</span><span class="dv">26</span>) {</span>
<span id="cb44-83"><a href="#cb44-83" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-84"><a href="#cb44-84" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_18_26)<span class="sc">%&gt;%</span></span>
<span id="cb44-85"><a href="#cb44-85" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-86"><a href="#cb44-86" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_18_26)</span>
<span id="cb44-87"><a href="#cb44-87" aria-hidden="true" tabindex="-1"></a>  staff_ratio_18_26<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_18_26,temp)</span>
<span id="cb44-88"><a href="#cb44-88" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-89"><a href="#cb44-89" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-90"><a href="#cb44-90" aria-hidden="true" tabindex="-1"></a><span class="co">#Second version with cutoffs 6 months later</span></span>
<span id="cb44-91"><a href="#cb44-91" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-92"><a href="#cb44-92" aria-hidden="true" tabindex="-1"></a>staff_ratio_24_32 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-93"><a href="#cb44-93" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_18_26)<span class="sc">%&gt;%</span></span>
<span id="cb44-94"><a href="#cb44-94" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">24</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-95"><a href="#cb44-95" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_18_26)</span>
<span id="cb44-96"><a href="#cb44-96" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-97"><a href="#cb44-97" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-98"><a href="#cb44-98" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">25</span><span class="sc">:</span><span class="dv">32</span>) {</span>
<span id="cb44-99"><a href="#cb44-99" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-100"><a href="#cb44-100" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_18_26)<span class="sc">%&gt;%</span></span>
<span id="cb44-101"><a href="#cb44-101" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-102"><a href="#cb44-102" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_18_26)</span>
<span id="cb44-103"><a href="#cb44-103" aria-hidden="true" tabindex="-1"></a>  staff_ratio_24_32<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_24_32,temp)</span>
<span id="cb44-104"><a href="#cb44-104" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-105"><a href="#cb44-105" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-106"><a href="#cb44-106" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-107"><a href="#cb44-107" aria-hidden="true" tabindex="-1"></a><span class="co">#Age 27-35</span></span>
<span id="cb44-108"><a href="#cb44-108" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-109"><a href="#cb44-109" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-110"><a href="#cb44-110" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-111"><a href="#cb44-111" aria-hidden="true" tabindex="-1"></a>staff_ratio_27_35 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-112"><a href="#cb44-112" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_27_35)<span class="sc">%&gt;%</span></span>
<span id="cb44-113"><a href="#cb44-113" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">27</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-114"><a href="#cb44-114" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_27_35)</span>
<span id="cb44-115"><a href="#cb44-115" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-116"><a href="#cb44-116" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-117"><a href="#cb44-117" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">28</span><span class="sc">:</span><span class="dv">35</span>) {</span>
<span id="cb44-118"><a href="#cb44-118" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-119"><a href="#cb44-119" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_27_35)<span class="sc">%&gt;%</span></span>
<span id="cb44-120"><a href="#cb44-120" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-121"><a href="#cb44-121" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_27_35)</span>
<span id="cb44-122"><a href="#cb44-122" aria-hidden="true" tabindex="-1"></a>  staff_ratio_27_35<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_27_35,temp)</span>
<span id="cb44-123"><a href="#cb44-123" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-124"><a href="#cb44-124" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-125"><a href="#cb44-125" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-126"><a href="#cb44-126" aria-hidden="true" tabindex="-1"></a><span class="co">#Second version with cutoffs 6 months later</span></span>
<span id="cb44-127"><a href="#cb44-127" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-128"><a href="#cb44-128" aria-hidden="true" tabindex="-1"></a>staff_ratio_33_41 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-129"><a href="#cb44-129" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_27_35)<span class="sc">%&gt;%</span></span>
<span id="cb44-130"><a href="#cb44-130" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">33</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-131"><a href="#cb44-131" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_27_35)</span>
<span id="cb44-132"><a href="#cb44-132" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-133"><a href="#cb44-133" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-134"><a href="#cb44-134" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">34</span><span class="sc">:</span><span class="dv">41</span>) {</span>
<span id="cb44-135"><a href="#cb44-135" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-136"><a href="#cb44-136" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_27_35)<span class="sc">%&gt;%</span></span>
<span id="cb44-137"><a href="#cb44-137" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-138"><a href="#cb44-138" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_27_35)</span>
<span id="cb44-139"><a href="#cb44-139" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb44-140"><a href="#cb44-140" aria-hidden="true" tabindex="-1"></a>  staff_ratio_33_41<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_33_41,temp)</span>
<span id="cb44-141"><a href="#cb44-141" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-142"><a href="#cb44-142" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-143"><a href="#cb44-143" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-144"><a href="#cb44-144" aria-hidden="true" tabindex="-1"></a><span class="co">#Age 36-47 (3 years)</span></span>
<span id="cb44-145"><a href="#cb44-145" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-146"><a href="#cb44-146" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-147"><a href="#cb44-147" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-148"><a href="#cb44-148" aria-hidden="true" tabindex="-1"></a>staff_ratio_36_47 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-149"><a href="#cb44-149" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_36_47)<span class="sc">%&gt;%</span></span>
<span id="cb44-150"><a href="#cb44-150" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">36</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-151"><a href="#cb44-151" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_36_47)</span>
<span id="cb44-152"><a href="#cb44-152" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-153"><a href="#cb44-153" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-154"><a href="#cb44-154" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">37</span><span class="sc">:</span><span class="dv">47</span>) {</span>
<span id="cb44-155"><a href="#cb44-155" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-156"><a href="#cb44-156" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_36_47)<span class="sc">%&gt;%</span></span>
<span id="cb44-157"><a href="#cb44-157" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-158"><a href="#cb44-158" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_36_47)</span>
<span id="cb44-159"><a href="#cb44-159" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb44-160"><a href="#cb44-160" aria-hidden="true" tabindex="-1"></a>  staff_ratio_36_47<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_36_47,temp)</span>
<span id="cb44-161"><a href="#cb44-161" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-162"><a href="#cb44-162" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-163"><a href="#cb44-163" aria-hidden="true" tabindex="-1"></a><span class="co">#Second version with cutoffs 6 months later</span></span>
<span id="cb44-164"><a href="#cb44-164" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-165"><a href="#cb44-165" aria-hidden="true" tabindex="-1"></a>staff_ratio_42_53 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-166"><a href="#cb44-166" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_36_47)<span class="sc">%&gt;%</span></span>
<span id="cb44-167"><a href="#cb44-167" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">42</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-168"><a href="#cb44-168" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_36_47)</span>
<span id="cb44-169"><a href="#cb44-169" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-170"><a href="#cb44-170" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-171"><a href="#cb44-171" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">43</span><span class="sc">:</span><span class="dv">53</span>) {</span>
<span id="cb44-172"><a href="#cb44-172" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-173"><a href="#cb44-173" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_36_47)<span class="sc">%&gt;%</span></span>
<span id="cb44-174"><a href="#cb44-174" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-175"><a href="#cb44-175" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_36_47)</span>
<span id="cb44-176"><a href="#cb44-176" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb44-177"><a href="#cb44-177" aria-hidden="true" tabindex="-1"></a>  staff_ratio_42_53<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_42_53,temp)</span>
<span id="cb44-178"><a href="#cb44-178" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-179"><a href="#cb44-179" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-180"><a href="#cb44-180" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-181"><a href="#cb44-181" aria-hidden="true" tabindex="-1"></a><span class="co">#Age 48-59 (4 years)</span></span>
<span id="cb44-182"><a href="#cb44-182" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-183"><a href="#cb44-183" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-184"><a href="#cb44-184" aria-hidden="true" tabindex="-1"></a>staff_ratio_48_59 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-185"><a href="#cb44-185" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_48_59)<span class="sc">%&gt;%</span></span>
<span id="cb44-186"><a href="#cb44-186" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">48</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-187"><a href="#cb44-187" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_48_59)</span>
<span id="cb44-188"><a href="#cb44-188" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-189"><a href="#cb44-189" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-190"><a href="#cb44-190" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">49</span><span class="sc">:</span><span class="dv">59</span>) {</span>
<span id="cb44-191"><a href="#cb44-191" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-192"><a href="#cb44-192" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_48_59)<span class="sc">%&gt;%</span></span>
<span id="cb44-193"><a href="#cb44-193" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-194"><a href="#cb44-194" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_48_59)</span>
<span id="cb44-195"><a href="#cb44-195" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb44-196"><a href="#cb44-196" aria-hidden="true" tabindex="-1"></a>  staff_ratio_48_59<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_48_59,temp)</span>
<span id="cb44-197"><a href="#cb44-197" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-198"><a href="#cb44-198" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-199"><a href="#cb44-199" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-200"><a href="#cb44-200" aria-hidden="true" tabindex="-1"></a><span class="co">#Second version with cutoffs 6 months later</span></span>
<span id="cb44-201"><a href="#cb44-201" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-202"><a href="#cb44-202" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-203"><a href="#cb44-203" aria-hidden="true" tabindex="-1"></a>staff_ratio_54_65 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-204"><a href="#cb44-204" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_48_59)<span class="sc">%&gt;%</span></span>
<span id="cb44-205"><a href="#cb44-205" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">54</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-206"><a href="#cb44-206" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_48_59)</span>
<span id="cb44-207"><a href="#cb44-207" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-208"><a href="#cb44-208" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-209"><a href="#cb44-209" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">55</span><span class="sc">:</span><span class="dv">65</span>) {</span>
<span id="cb44-210"><a href="#cb44-210" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-211"><a href="#cb44-211" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_48_59)<span class="sc">%&gt;%</span></span>
<span id="cb44-212"><a href="#cb44-212" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-213"><a href="#cb44-213" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_48_59)</span>
<span id="cb44-214"><a href="#cb44-214" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb44-215"><a href="#cb44-215" aria-hidden="true" tabindex="-1"></a>  staff_ratio_54_65<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_54_65,temp)</span>
<span id="cb44-216"><a href="#cb44-216" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-217"><a href="#cb44-217" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-218"><a href="#cb44-218" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-219"><a href="#cb44-219" aria-hidden="true" tabindex="-1"></a><span class="co">#Age 60-71 (5 years)</span></span>
<span id="cb44-220"><a href="#cb44-220" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-221"><a href="#cb44-221" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-222"><a href="#cb44-222" aria-hidden="true" tabindex="-1"></a>staff_ratio_60_71 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-223"><a href="#cb44-223" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_60_71)<span class="sc">%&gt;%</span></span>
<span id="cb44-224"><a href="#cb44-224" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">60</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-225"><a href="#cb44-225" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_60_71)</span>
<span id="cb44-226"><a href="#cb44-226" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-227"><a href="#cb44-227" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-228"><a href="#cb44-228" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">61</span><span class="sc">:</span><span class="dv">71</span>) {</span>
<span id="cb44-229"><a href="#cb44-229" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-230"><a href="#cb44-230" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_60_71)<span class="sc">%&gt;%</span></span>
<span id="cb44-231"><a href="#cb44-231" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-232"><a href="#cb44-232" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_60_71)</span>
<span id="cb44-233"><a href="#cb44-233" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb44-234"><a href="#cb44-234" aria-hidden="true" tabindex="-1"></a>  staff_ratio_60_71<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_60_71,temp)</span>
<span id="cb44-235"><a href="#cb44-235" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-236"><a href="#cb44-236" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-237"><a href="#cb44-237" aria-hidden="true" tabindex="-1"></a><span class="co">#Second version with cutoffs 6 months later</span></span>
<span id="cb44-238"><a href="#cb44-238" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-239"><a href="#cb44-239" aria-hidden="true" tabindex="-1"></a>staff_ratio_66_77 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-240"><a href="#cb44-240" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_60_71)<span class="sc">%&gt;%</span></span>
<span id="cb44-241"><a href="#cb44-241" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">66</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-242"><a href="#cb44-242" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_60_71)</span>
<span id="cb44-243"><a href="#cb44-243" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-244"><a href="#cb44-244" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-245"><a href="#cb44-245" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">67</span><span class="sc">:</span><span class="dv">77</span>) {</span>
<span id="cb44-246"><a href="#cb44-246" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-247"><a href="#cb44-247" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_60_71)<span class="sc">%&gt;%</span></span>
<span id="cb44-248"><a href="#cb44-248" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-249"><a href="#cb44-249" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_60_71)</span>
<span id="cb44-250"><a href="#cb44-250" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb44-251"><a href="#cb44-251" aria-hidden="true" tabindex="-1"></a>  staff_ratio_66_77<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_66_77,temp)</span>
<span id="cb44-252"><a href="#cb44-252" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-253"><a href="#cb44-253" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-254"><a href="#cb44-254" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-255"><a href="#cb44-255" aria-hidden="true" tabindex="-1"></a><span class="co">#Age 72-83 (6 years)</span></span>
<span id="cb44-256"><a href="#cb44-256" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-257"><a href="#cb44-257" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-258"><a href="#cb44-258" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-259"><a href="#cb44-259" aria-hidden="true" tabindex="-1"></a>staff_ratio_72_83 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-260"><a href="#cb44-260" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_72_83)<span class="sc">%&gt;%</span></span>
<span id="cb44-261"><a href="#cb44-261" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">72</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-262"><a href="#cb44-262" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_72_83)</span>
<span id="cb44-263"><a href="#cb44-263" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-264"><a href="#cb44-264" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-265"><a href="#cb44-265" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">73</span><span class="sc">:</span><span class="dv">83</span>) {</span>
<span id="cb44-266"><a href="#cb44-266" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-267"><a href="#cb44-267" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_72_83)<span class="sc">%&gt;%</span></span>
<span id="cb44-268"><a href="#cb44-268" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-269"><a href="#cb44-269" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_72_83)</span>
<span id="cb44-270"><a href="#cb44-270" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb44-271"><a href="#cb44-271" aria-hidden="true" tabindex="-1"></a>  staff_ratio_72_83<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_72_83,temp)</span>
<span id="cb44-272"><a href="#cb44-272" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-273"><a href="#cb44-273" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-274"><a href="#cb44-274" aria-hidden="true" tabindex="-1"></a><span class="co">#Second version with cutoffs 6 months later</span></span>
<span id="cb44-275"><a href="#cb44-275" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-276"><a href="#cb44-276" aria-hidden="true" tabindex="-1"></a>staff_ratio_78_89 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-277"><a href="#cb44-277" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_72_83)<span class="sc">%&gt;%</span></span>
<span id="cb44-278"><a href="#cb44-278" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">78</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-279"><a href="#cb44-279" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_72_83)</span>
<span id="cb44-280"><a href="#cb44-280" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-281"><a href="#cb44-281" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-282"><a href="#cb44-282" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">79</span><span class="sc">:</span><span class="dv">89</span>) {</span>
<span id="cb44-283"><a href="#cb44-283" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-284"><a href="#cb44-284" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_72_83)<span class="sc">%&gt;%</span></span>
<span id="cb44-285"><a href="#cb44-285" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-286"><a href="#cb44-286" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_72_83)</span>
<span id="cb44-287"><a href="#cb44-287" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb44-288"><a href="#cb44-288" aria-hidden="true" tabindex="-1"></a>  staff_ratio_78_89<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_78_89,temp)</span>
<span id="cb44-289"><a href="#cb44-289" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-290"><a href="#cb44-290" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-291"><a href="#cb44-291" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-292"><a href="#cb44-292" aria-hidden="true" tabindex="-1"></a><span class="co">#Age 84-95 (7 years)</span></span>
<span id="cb44-293"><a href="#cb44-293" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-294"><a href="#cb44-294" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-295"><a href="#cb44-295" aria-hidden="true" tabindex="-1"></a>staff_ratio_84_95 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-296"><a href="#cb44-296" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_84_95)<span class="sc">%&gt;%</span></span>
<span id="cb44-297"><a href="#cb44-297" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">84</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-298"><a href="#cb44-298" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_84_95)</span>
<span id="cb44-299"><a href="#cb44-299" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-300"><a href="#cb44-300" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-301"><a href="#cb44-301" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">85</span><span class="sc">:</span><span class="dv">95</span>) {</span>
<span id="cb44-302"><a href="#cb44-302" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-303"><a href="#cb44-303" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_84_95)<span class="sc">%&gt;%</span></span>
<span id="cb44-304"><a href="#cb44-304" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-305"><a href="#cb44-305" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_84_95)</span>
<span id="cb44-306"><a href="#cb44-306" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb44-307"><a href="#cb44-307" aria-hidden="true" tabindex="-1"></a>  staff_ratio_84_95<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_84_95,temp)</span>
<span id="cb44-308"><a href="#cb44-308" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-309"><a href="#cb44-309" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-310"><a href="#cb44-310" aria-hidden="true" tabindex="-1"></a><span class="co">#Second version with cutoffs 6 months later</span></span>
<span id="cb44-311"><a href="#cb44-311" aria-hidden="true" tabindex="-1"></a>staff_ratio_90_101 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-312"><a href="#cb44-312" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_84_95)<span class="sc">%&gt;%</span></span>
<span id="cb44-313"><a href="#cb44-313" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">90</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-314"><a href="#cb44-314" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_84_95)</span>
<span id="cb44-315"><a href="#cb44-315" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-316"><a href="#cb44-316" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-317"><a href="#cb44-317" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">91</span><span class="sc">:</span><span class="dv">101</span>) {</span>
<span id="cb44-318"><a href="#cb44-318" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-319"><a href="#cb44-319" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_84_95)<span class="sc">%&gt;%</span></span>
<span id="cb44-320"><a href="#cb44-320" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-321"><a href="#cb44-321" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_84_95)</span>
<span id="cb44-322"><a href="#cb44-322" aria-hidden="true" tabindex="-1"></a>  staff_ratio_90_101<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_90_101,temp)</span>
<span id="cb44-323"><a href="#cb44-323" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-324"><a href="#cb44-324" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-325"><a href="#cb44-325" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-326"><a href="#cb44-326" aria-hidden="true" tabindex="-1"></a><span class="co">#Age 96-119 (8-9 years old)</span></span>
<span id="cb44-327"><a href="#cb44-327" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-328"><a href="#cb44-328" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-329"><a href="#cb44-329" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-330"><a href="#cb44-330" aria-hidden="true" tabindex="-1"></a>staff_ratio_96_119 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-331"><a href="#cb44-331" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_96_119)<span class="sc">%&gt;%</span></span>
<span id="cb44-332"><a href="#cb44-332" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">96</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-333"><a href="#cb44-333" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_96_119)</span>
<span id="cb44-334"><a href="#cb44-334" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-335"><a href="#cb44-335" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-336"><a href="#cb44-336" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">97</span><span class="sc">:</span><span class="dv">119</span>) {</span>
<span id="cb44-337"><a href="#cb44-337" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-338"><a href="#cb44-338" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_96_119)<span class="sc">%&gt;%</span></span>
<span id="cb44-339"><a href="#cb44-339" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-340"><a href="#cb44-340" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_96_119)</span>
<span id="cb44-341"><a href="#cb44-341" aria-hidden="true" tabindex="-1"></a>  staff_ratio_96_119<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_96_119,temp)</span>
<span id="cb44-342"><a href="#cb44-342" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-343"><a href="#cb44-343" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-344"><a href="#cb44-344" aria-hidden="true" tabindex="-1"></a><span class="co">#Second version with cutoffs 6 months later</span></span>
<span id="cb44-345"><a href="#cb44-345" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-346"><a href="#cb44-346" aria-hidden="true" tabindex="-1"></a>staff_ratio_102_125 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-347"><a href="#cb44-347" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_96_119)<span class="sc">%&gt;%</span></span>
<span id="cb44-348"><a href="#cb44-348" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">102</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-349"><a href="#cb44-349" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_96_119)</span>
<span id="cb44-350"><a href="#cb44-350" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-351"><a href="#cb44-351" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-352"><a href="#cb44-352" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">103</span><span class="sc">:</span><span class="dv">125</span>) {</span>
<span id="cb44-353"><a href="#cb44-353" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-354"><a href="#cb44-354" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_96_119)<span class="sc">%&gt;%</span></span>
<span id="cb44-355"><a href="#cb44-355" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-356"><a href="#cb44-356" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_96_119)</span>
<span id="cb44-357"><a href="#cb44-357" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb44-358"><a href="#cb44-358" aria-hidden="true" tabindex="-1"></a>  staff_ratio_102_125 <span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_102_125 ,temp)</span>
<span id="cb44-359"><a href="#cb44-359" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-360"><a href="#cb44-360" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-361"><a href="#cb44-361" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-362"><a href="#cb44-362" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-363"><a href="#cb44-363" aria-hidden="true" tabindex="-1"></a><span class="co">#Age 120+ (10+ years)</span></span>
<span id="cb44-364"><a href="#cb44-364" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-365"><a href="#cb44-365" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-366"><a href="#cb44-366" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-367"><a href="#cb44-367" aria-hidden="true" tabindex="-1"></a>staff_ratio_120 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-368"><a href="#cb44-368" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_120)<span class="sc">%&gt;%</span></span>
<span id="cb44-369"><a href="#cb44-369" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">120</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-370"><a href="#cb44-370" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_120)</span>
<span id="cb44-371"><a href="#cb44-371" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-372"><a href="#cb44-372" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-373"><a href="#cb44-373" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">121</span><span class="sc">:</span><span class="dv">160</span>) {</span>
<span id="cb44-374"><a href="#cb44-374" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-375"><a href="#cb44-375" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_120)<span class="sc">%&gt;%</span></span>
<span id="cb44-376"><a href="#cb44-376" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-377"><a href="#cb44-377" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_120)</span>
<span id="cb44-378"><a href="#cb44-378" aria-hidden="true" tabindex="-1"></a>  staff_ratio_120<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_120,temp)</span>
<span id="cb44-379"><a href="#cb44-379" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-380"><a href="#cb44-380" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-381"><a href="#cb44-381" aria-hidden="true" tabindex="-1"></a><span class="co">#Second version with cutoffs 6 months later</span></span>
<span id="cb44-382"><a href="#cb44-382" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-383"><a href="#cb44-383" aria-hidden="true" tabindex="-1"></a>staff_ratio_126 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-384"><a href="#cb44-384" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_120)<span class="sc">%&gt;%</span></span>
<span id="cb44-385"><a href="#cb44-385" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">126</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-386"><a href="#cb44-386" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_120)</span>
<span id="cb44-387"><a href="#cb44-387" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-388"><a href="#cb44-388" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-389"><a href="#cb44-389" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">127</span><span class="sc">:</span><span class="dv">160</span>) {</span>
<span id="cb44-390"><a href="#cb44-390" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-391"><a href="#cb44-391" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_120)<span class="sc">%&gt;%</span></span>
<span id="cb44-392"><a href="#cb44-392" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-393"><a href="#cb44-393" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_120)</span>
<span id="cb44-394"><a href="#cb44-394" aria-hidden="true" tabindex="-1"></a>  staff_ratio_126<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_126,temp)</span>
<span id="cb44-395"><a href="#cb44-395" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-396"><a href="#cb44-396" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-397"><a href="#cb44-397" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-398"><a href="#cb44-398" aria-hidden="true" tabindex="-1"></a>panel_staff_ratio_6m <span class="ot">&lt;-</span> <span class="fu">rbind</span>(staff_ratio_0_14, staff_ratio_15_23, staff_ratio_24_32, staff_ratio_33_41, staff_ratio_42_53, </span>
<span id="cb44-399"><a href="#cb44-399" aria-hidden="true" tabindex="-1"></a>                              staff_ratio_54_65, staff_ratio_66_77, staff_ratio_78_89,staff_ratio_90_101 , </span>
<span id="cb44-400"><a href="#cb44-400" aria-hidden="true" tabindex="-1"></a>                              staff_ratio_102_125,staff_ratio_126)<span class="sc">%&gt;%</span></span>
<span id="cb44-401"><a href="#cb44-401" aria-hidden="true" tabindex="-1"></a>                              <span class="co">#generate staff-to-child from child-to-staff ratio with 6 months lag</span></span>
<span id="cb44-402"><a href="#cb44-402" aria-hidden="true" tabindex="-1"></a>                              <span class="fu">mutate</span>(<span class="at">staff_ratio_6m=</span><span class="dv">1</span><span class="sc">/</span>child_staff_ratio)<span class="sc">%&gt;%</span></span>
<span id="cb44-403"><a href="#cb44-403" aria-hidden="true" tabindex="-1"></a>                              <span class="fu">select</span>(<span class="sc">-</span>child_staff_ratio)  </span>
<span id="cb44-404"><a href="#cb44-404" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-405"><a href="#cb44-405" aria-hidden="true" tabindex="-1"></a>panel_staff_ratio_2002 <span class="ot">&lt;-</span> <span class="fu">rbind</span>(staff_ratio_0_8, staff_ratio_9_17, staff_ratio_18_26, staff_ratio_27_35, staff_ratio_36_47, </span>
<span id="cb44-406"><a href="#cb44-406" aria-hidden="true" tabindex="-1"></a>                                staff_ratio_48_59, staff_ratio_60_71, staff_ratio_72_83,staff_ratio_84_95 , </span>
<span id="cb44-407"><a href="#cb44-407" aria-hidden="true" tabindex="-1"></a>                                staff_ratio_96_119,staff_ratio_120)<span class="sc">%&gt;%</span></span>
<span id="cb44-408"><a href="#cb44-408" aria-hidden="true" tabindex="-1"></a>                                <span class="co">#generate staff-to-child from child-to-staff ratio</span></span>
<span id="cb44-409"><a href="#cb44-409" aria-hidden="true" tabindex="-1"></a>                                <span class="fu">mutate</span>(<span class="at">staff_ratio=</span><span class="dv">1</span><span class="sc">/</span>child_staff_ratio)<span class="sc">%&gt;%</span></span>
<span id="cb44-410"><a href="#cb44-410" aria-hidden="true" tabindex="-1"></a>                                <span class="fu">select</span>(<span class="sc">-</span>child_staff_ratio) <span class="sc">%&gt;%</span></span>
<span id="cb44-411"><a href="#cb44-411" aria-hidden="true" tabindex="-1"></a>                                <span class="fu">merge</span>(panel_staff_ratio_6m)<span class="sc">%&gt;%</span></span>
<span id="cb44-412"><a href="#cb44-412" aria-hidden="true" tabindex="-1"></a>                                <span class="fu">mutate</span>(<span class="at">year=</span><span class="dv">2002</span>)</span>
<span id="cb44-413"><a href="#cb44-413" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-414"><a href="#cb44-414" aria-hidden="true" tabindex="-1"></a><span class="co">#Use 2002 ratios for 1997 interview</span></span>
<span id="cb44-415"><a href="#cb44-415" aria-hidden="true" tabindex="-1"></a>panel_staff_ratio_1997 <span class="ot">&lt;-</span> panel_staff_ratio_2002<span class="sc">%&gt;%</span></span>
<span id="cb44-416"><a href="#cb44-416" aria-hidden="true" tabindex="-1"></a><span class="fu">mutate</span>(<span class="at">year=</span><span class="dv">1997</span>)</span>
<span id="cb44-417"><a href="#cb44-417" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-418"><a href="#cb44-418" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-419"><a href="#cb44-419" aria-hidden="true" tabindex="-1"></a><span class="co">#Delete all objects that start with staff_ratio to generate a 2007 panel</span></span>
<span id="cb44-420"><a href="#cb44-420" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-421"><a href="#cb44-421" aria-hidden="true" tabindex="-1"></a><span class="co"># List all objects in the current environment</span></span>
<span id="cb44-422"><a href="#cb44-422" aria-hidden="true" tabindex="-1"></a>objects <span class="ot">&lt;-</span> <span class="fu">ls</span>()</span>
<span id="cb44-423"><a href="#cb44-423" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-424"><a href="#cb44-424" aria-hidden="true" tabindex="-1"></a><span class="co"># Identify objects starting with "staff_ratio"</span></span>
<span id="cb44-425"><a href="#cb44-425" aria-hidden="true" tabindex="-1"></a>objects_to_delete <span class="ot">&lt;-</span> objects[<span class="fu">grep</span>(<span class="st">"^staff_ratio"</span>, objects)]</span>
<span id="cb44-426"><a href="#cb44-426" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-427"><a href="#cb44-427" aria-hidden="true" tabindex="-1"></a><span class="co"># Delete objects starting with "staff_ratio"</span></span>
<span id="cb44-428"><a href="#cb44-428" aria-hidden="true" tabindex="-1"></a><span class="fu">rm</span>(<span class="at">list =</span> objects_to_delete)</span>
<span id="cb44-429"><a href="#cb44-429" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-430"><a href="#cb44-430" aria-hidden="true" tabindex="-1"></a><span class="do">###############################################################</span></span>
<span id="cb44-431"><a href="#cb44-431" aria-hidden="true" tabindex="-1"></a><span class="do">##########################2007 ratios##########################</span></span>
<span id="cb44-432"><a href="#cb44-432" aria-hidden="true" tabindex="-1"></a><span class="do">###############################################################</span></span>
<span id="cb44-433"><a href="#cb44-433" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-434"><a href="#cb44-434" aria-hidden="true" tabindex="-1"></a><span class="co">#Create a panel of mandatory staff-child ratio by state/age of child in months</span></span>
<span id="cb44-435"><a href="#cb44-435" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-436"><a href="#cb44-436" aria-hidden="true" tabindex="-1"></a>staff_ratio <span class="ot">&lt;-</span> readxl<span class="sc">::</span><span class="fu">read_excel</span>(<span class="st">"../../../data/data_PSID/cds/staff-child-ratios/Ratios_Center_Based_2007.xlsx"</span>)</span>
<span id="cb44-437"><a href="#cb44-437" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-438"><a href="#cb44-438" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-439"><a href="#cb44-439" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-440"><a href="#cb44-440" aria-hidden="true" tabindex="-1"></a><span class="co">#Age 0-8 months</span></span>
<span id="cb44-441"><a href="#cb44-441" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-442"><a href="#cb44-442" aria-hidden="true" tabindex="-1"></a>staff_ratio_0_8 <span class="ot">&lt;-</span>  staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-443"><a href="#cb44-443" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_0_8)<span class="sc">%&gt;%</span></span>
<span id="cb44-444"><a href="#cb44-444" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">0</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-445"><a href="#cb44-445" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_0_8)</span>
<span id="cb44-446"><a href="#cb44-446" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-447"><a href="#cb44-447" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-448"><a href="#cb44-448" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span><span class="dv">8</span>) {</span>
<span id="cb44-449"><a href="#cb44-449" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span>  staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-450"><a href="#cb44-450" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_0_8)<span class="sc">%&gt;%</span></span>
<span id="cb44-451"><a href="#cb44-451" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-452"><a href="#cb44-452" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_0_8)</span>
<span id="cb44-453"><a href="#cb44-453" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb44-454"><a href="#cb44-454" aria-hidden="true" tabindex="-1"></a>  staff_ratio_0_8<span class="ot">=</span> <span class="fu">rbind</span>( staff_ratio_0_8,temp)</span>
<span id="cb44-455"><a href="#cb44-455" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-456"><a href="#cb44-456" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-457"><a href="#cb44-457" aria-hidden="true" tabindex="-1"></a><span class="co">#Second version with cutoffs 6 months later</span></span>
<span id="cb44-458"><a href="#cb44-458" aria-hidden="true" tabindex="-1"></a>staff_ratio_0_14 <span class="ot">&lt;-</span>  staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-459"><a href="#cb44-459" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_0_8)<span class="sc">%&gt;%</span></span>
<span id="cb44-460"><a href="#cb44-460" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">0</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-461"><a href="#cb44-461" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_0_8)</span>
<span id="cb44-462"><a href="#cb44-462" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-463"><a href="#cb44-463" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-464"><a href="#cb44-464" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span><span class="dv">14</span>) {</span>
<span id="cb44-465"><a href="#cb44-465" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span>  staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-466"><a href="#cb44-466" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_0_8)<span class="sc">%&gt;%</span></span>
<span id="cb44-467"><a href="#cb44-467" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-468"><a href="#cb44-468" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_0_8)</span>
<span id="cb44-469"><a href="#cb44-469" aria-hidden="true" tabindex="-1"></a>  staff_ratio_0_14<span class="ot">=</span> <span class="fu">rbind</span>(staff_ratio_0_14,temp)</span>
<span id="cb44-470"><a href="#cb44-470" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-471"><a href="#cb44-471" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-472"><a href="#cb44-472" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-473"><a href="#cb44-473" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-474"><a href="#cb44-474" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-475"><a href="#cb44-475" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-476"><a href="#cb44-476" aria-hidden="true" tabindex="-1"></a><span class="co">#Age 9-17 months</span></span>
<span id="cb44-477"><a href="#cb44-477" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-478"><a href="#cb44-478" aria-hidden="true" tabindex="-1"></a>staff_ratio_9_17 <span class="ot">&lt;-</span>  staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-479"><a href="#cb44-479" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_9_17)<span class="sc">%&gt;%</span></span>
<span id="cb44-480"><a href="#cb44-480" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">9</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-481"><a href="#cb44-481" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_9_17)</span>
<span id="cb44-482"><a href="#cb44-482" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-483"><a href="#cb44-483" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-484"><a href="#cb44-484" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">10</span><span class="sc">:</span><span class="dv">17</span>) {</span>
<span id="cb44-485"><a href="#cb44-485" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span>  staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-486"><a href="#cb44-486" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_9_17)<span class="sc">%&gt;%</span></span>
<span id="cb44-487"><a href="#cb44-487" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-488"><a href="#cb44-488" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_9_17)</span>
<span id="cb44-489"><a href="#cb44-489" aria-hidden="true" tabindex="-1"></a>  staff_ratio_9_17<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_9_17,temp)</span>
<span id="cb44-490"><a href="#cb44-490" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-491"><a href="#cb44-491" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-492"><a href="#cb44-492" aria-hidden="true" tabindex="-1"></a><span class="co">#Second version with cutoffs 6 months later</span></span>
<span id="cb44-493"><a href="#cb44-493" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-494"><a href="#cb44-494" aria-hidden="true" tabindex="-1"></a>staff_ratio_15_23 <span class="ot">&lt;-</span>  staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-495"><a href="#cb44-495" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_9_17)<span class="sc">%&gt;%</span></span>
<span id="cb44-496"><a href="#cb44-496" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">15</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-497"><a href="#cb44-497" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_9_17)</span>
<span id="cb44-498"><a href="#cb44-498" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-499"><a href="#cb44-499" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-500"><a href="#cb44-500" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">16</span><span class="sc">:</span><span class="dv">23</span>) {</span>
<span id="cb44-501"><a href="#cb44-501" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span>  staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-502"><a href="#cb44-502" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_9_17)<span class="sc">%&gt;%</span></span>
<span id="cb44-503"><a href="#cb44-503" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-504"><a href="#cb44-504" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_9_17)</span>
<span id="cb44-505"><a href="#cb44-505" aria-hidden="true" tabindex="-1"></a>  staff_ratio_15_23<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_15_23,temp)</span>
<span id="cb44-506"><a href="#cb44-506" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-507"><a href="#cb44-507" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-508"><a href="#cb44-508" aria-hidden="true" tabindex="-1"></a><span class="co">#Age 18-26</span></span>
<span id="cb44-509"><a href="#cb44-509" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-510"><a href="#cb44-510" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-511"><a href="#cb44-511" aria-hidden="true" tabindex="-1"></a>staff_ratio_18_26 <span class="ot">&lt;-</span>  staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-512"><a href="#cb44-512" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_18_26)<span class="sc">%&gt;%</span></span>
<span id="cb44-513"><a href="#cb44-513" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">18</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-514"><a href="#cb44-514" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_18_26)</span>
<span id="cb44-515"><a href="#cb44-515" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-516"><a href="#cb44-516" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-517"><a href="#cb44-517" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">19</span><span class="sc">:</span><span class="dv">26</span>) {</span>
<span id="cb44-518"><a href="#cb44-518" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span>  staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-519"><a href="#cb44-519" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_18_26)<span class="sc">%&gt;%</span></span>
<span id="cb44-520"><a href="#cb44-520" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-521"><a href="#cb44-521" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_18_26)</span>
<span id="cb44-522"><a href="#cb44-522" aria-hidden="true" tabindex="-1"></a>  staff_ratio_18_26<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_18_26,temp)</span>
<span id="cb44-523"><a href="#cb44-523" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-524"><a href="#cb44-524" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-525"><a href="#cb44-525" aria-hidden="true" tabindex="-1"></a><span class="co">#Second version with cutoffs 6 months later</span></span>
<span id="cb44-526"><a href="#cb44-526" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-527"><a href="#cb44-527" aria-hidden="true" tabindex="-1"></a>staff_ratio_24_32 <span class="ot">&lt;-</span>  staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-528"><a href="#cb44-528" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_18_26)<span class="sc">%&gt;%</span></span>
<span id="cb44-529"><a href="#cb44-529" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">24</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-530"><a href="#cb44-530" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_18_26)</span>
<span id="cb44-531"><a href="#cb44-531" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-532"><a href="#cb44-532" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-533"><a href="#cb44-533" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">25</span><span class="sc">:</span><span class="dv">32</span>) {</span>
<span id="cb44-534"><a href="#cb44-534" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span>  staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-535"><a href="#cb44-535" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_18_26)<span class="sc">%&gt;%</span></span>
<span id="cb44-536"><a href="#cb44-536" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-537"><a href="#cb44-537" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_18_26)</span>
<span id="cb44-538"><a href="#cb44-538" aria-hidden="true" tabindex="-1"></a>  staff_ratio_24_32<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_24_32,temp)</span>
<span id="cb44-539"><a href="#cb44-539" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-540"><a href="#cb44-540" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-541"><a href="#cb44-541" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-542"><a href="#cb44-542" aria-hidden="true" tabindex="-1"></a><span class="co">#Age 27-35</span></span>
<span id="cb44-543"><a href="#cb44-543" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-544"><a href="#cb44-544" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-545"><a href="#cb44-545" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-546"><a href="#cb44-546" aria-hidden="true" tabindex="-1"></a>staff_ratio_27_35 <span class="ot">&lt;-</span>  staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-547"><a href="#cb44-547" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_27_35)<span class="sc">%&gt;%</span></span>
<span id="cb44-548"><a href="#cb44-548" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">27</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-549"><a href="#cb44-549" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_27_35)</span>
<span id="cb44-550"><a href="#cb44-550" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-551"><a href="#cb44-551" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-552"><a href="#cb44-552" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">28</span><span class="sc">:</span><span class="dv">35</span>) {</span>
<span id="cb44-553"><a href="#cb44-553" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span>  staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-554"><a href="#cb44-554" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_27_35)<span class="sc">%&gt;%</span></span>
<span id="cb44-555"><a href="#cb44-555" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-556"><a href="#cb44-556" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_27_35)</span>
<span id="cb44-557"><a href="#cb44-557" aria-hidden="true" tabindex="-1"></a>  staff_ratio_27_35<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_27_35,temp)</span>
<span id="cb44-558"><a href="#cb44-558" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-559"><a href="#cb44-559" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-560"><a href="#cb44-560" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-561"><a href="#cb44-561" aria-hidden="true" tabindex="-1"></a><span class="co">#Second version with cutoffs 6 months later</span></span>
<span id="cb44-562"><a href="#cb44-562" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-563"><a href="#cb44-563" aria-hidden="true" tabindex="-1"></a>staff_ratio_33_41 <span class="ot">&lt;-</span>  staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-564"><a href="#cb44-564" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_27_35)<span class="sc">%&gt;%</span></span>
<span id="cb44-565"><a href="#cb44-565" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">33</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-566"><a href="#cb44-566" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_27_35)</span>
<span id="cb44-567"><a href="#cb44-567" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-568"><a href="#cb44-568" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-569"><a href="#cb44-569" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">34</span><span class="sc">:</span><span class="dv">41</span>) {</span>
<span id="cb44-570"><a href="#cb44-570" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span>  staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-571"><a href="#cb44-571" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_27_35)<span class="sc">%&gt;%</span></span>
<span id="cb44-572"><a href="#cb44-572" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-573"><a href="#cb44-573" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_27_35)</span>
<span id="cb44-574"><a href="#cb44-574" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb44-575"><a href="#cb44-575" aria-hidden="true" tabindex="-1"></a>  staff_ratio_33_41<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_33_41,temp)</span>
<span id="cb44-576"><a href="#cb44-576" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-577"><a href="#cb44-577" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-578"><a href="#cb44-578" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-579"><a href="#cb44-579" aria-hidden="true" tabindex="-1"></a><span class="co">#Age 36-47 (3 years)</span></span>
<span id="cb44-580"><a href="#cb44-580" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-581"><a href="#cb44-581" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-582"><a href="#cb44-582" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-583"><a href="#cb44-583" aria-hidden="true" tabindex="-1"></a>staff_ratio_36_47 <span class="ot">&lt;-</span>  staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-584"><a href="#cb44-584" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_36_47)<span class="sc">%&gt;%</span></span>
<span id="cb44-585"><a href="#cb44-585" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">36</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-586"><a href="#cb44-586" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_36_47)</span>
<span id="cb44-587"><a href="#cb44-587" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-588"><a href="#cb44-588" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-589"><a href="#cb44-589" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">37</span><span class="sc">:</span><span class="dv">47</span>) {</span>
<span id="cb44-590"><a href="#cb44-590" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span>  staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-591"><a href="#cb44-591" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_36_47)<span class="sc">%&gt;%</span></span>
<span id="cb44-592"><a href="#cb44-592" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-593"><a href="#cb44-593" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_36_47)</span>
<span id="cb44-594"><a href="#cb44-594" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb44-595"><a href="#cb44-595" aria-hidden="true" tabindex="-1"></a>  staff_ratio_36_47<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_36_47,temp)</span>
<span id="cb44-596"><a href="#cb44-596" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-597"><a href="#cb44-597" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-598"><a href="#cb44-598" aria-hidden="true" tabindex="-1"></a><span class="co">#Second version with cutoffs 6 months later</span></span>
<span id="cb44-599"><a href="#cb44-599" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-600"><a href="#cb44-600" aria-hidden="true" tabindex="-1"></a>staff_ratio_42_53 <span class="ot">&lt;-</span>  staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-601"><a href="#cb44-601" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_36_47)<span class="sc">%&gt;%</span></span>
<span id="cb44-602"><a href="#cb44-602" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">42</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-603"><a href="#cb44-603" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_36_47)</span>
<span id="cb44-604"><a href="#cb44-604" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-605"><a href="#cb44-605" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-606"><a href="#cb44-606" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">43</span><span class="sc">:</span><span class="dv">53</span>) {</span>
<span id="cb44-607"><a href="#cb44-607" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-608"><a href="#cb44-608" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_36_47)<span class="sc">%&gt;%</span></span>
<span id="cb44-609"><a href="#cb44-609" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-610"><a href="#cb44-610" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_36_47)</span>
<span id="cb44-611"><a href="#cb44-611" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb44-612"><a href="#cb44-612" aria-hidden="true" tabindex="-1"></a>  staff_ratio_42_53<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_42_53,temp)</span>
<span id="cb44-613"><a href="#cb44-613" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-614"><a href="#cb44-614" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-615"><a href="#cb44-615" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-616"><a href="#cb44-616" aria-hidden="true" tabindex="-1"></a><span class="co">#Age 48-59 (4 years)</span></span>
<span id="cb44-617"><a href="#cb44-617" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-618"><a href="#cb44-618" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-619"><a href="#cb44-619" aria-hidden="true" tabindex="-1"></a>staff_ratio_48_59 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-620"><a href="#cb44-620" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_48_59)<span class="sc">%&gt;%</span></span>
<span id="cb44-621"><a href="#cb44-621" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">48</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-622"><a href="#cb44-622" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_48_59)</span>
<span id="cb44-623"><a href="#cb44-623" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-624"><a href="#cb44-624" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-625"><a href="#cb44-625" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">49</span><span class="sc">:</span><span class="dv">59</span>) {</span>
<span id="cb44-626"><a href="#cb44-626" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-627"><a href="#cb44-627" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_48_59)<span class="sc">%&gt;%</span></span>
<span id="cb44-628"><a href="#cb44-628" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-629"><a href="#cb44-629" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_48_59)</span>
<span id="cb44-630"><a href="#cb44-630" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb44-631"><a href="#cb44-631" aria-hidden="true" tabindex="-1"></a>  staff_ratio_48_59<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_48_59,temp)</span>
<span id="cb44-632"><a href="#cb44-632" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-633"><a href="#cb44-633" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-634"><a href="#cb44-634" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-635"><a href="#cb44-635" aria-hidden="true" tabindex="-1"></a><span class="co">#Second version with cutoffs 6 months later</span></span>
<span id="cb44-636"><a href="#cb44-636" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-637"><a href="#cb44-637" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-638"><a href="#cb44-638" aria-hidden="true" tabindex="-1"></a>staff_ratio_54_65 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-639"><a href="#cb44-639" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_48_59)<span class="sc">%&gt;%</span></span>
<span id="cb44-640"><a href="#cb44-640" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">54</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-641"><a href="#cb44-641" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_48_59)</span>
<span id="cb44-642"><a href="#cb44-642" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-643"><a href="#cb44-643" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-644"><a href="#cb44-644" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">55</span><span class="sc">:</span><span class="dv">65</span>) {</span>
<span id="cb44-645"><a href="#cb44-645" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-646"><a href="#cb44-646" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_48_59)<span class="sc">%&gt;%</span></span>
<span id="cb44-647"><a href="#cb44-647" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-648"><a href="#cb44-648" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_48_59)</span>
<span id="cb44-649"><a href="#cb44-649" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb44-650"><a href="#cb44-650" aria-hidden="true" tabindex="-1"></a>  staff_ratio_54_65<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_54_65,temp)</span>
<span id="cb44-651"><a href="#cb44-651" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-652"><a href="#cb44-652" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-653"><a href="#cb44-653" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-654"><a href="#cb44-654" aria-hidden="true" tabindex="-1"></a><span class="co">#Age 60-119 (5-10 years)</span></span>
<span id="cb44-655"><a href="#cb44-655" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-656"><a href="#cb44-656" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-657"><a href="#cb44-657" aria-hidden="true" tabindex="-1"></a>staff_ratio_60_119 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-658"><a href="#cb44-658" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_60_119)<span class="sc">%&gt;%</span></span>
<span id="cb44-659"><a href="#cb44-659" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">60</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-660"><a href="#cb44-660" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_60_119)</span>
<span id="cb44-661"><a href="#cb44-661" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-662"><a href="#cb44-662" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-663"><a href="#cb44-663" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">61</span><span class="sc">:</span><span class="dv">119</span>) {</span>
<span id="cb44-664"><a href="#cb44-664" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-665"><a href="#cb44-665" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_60_119)<span class="sc">%&gt;%</span></span>
<span id="cb44-666"><a href="#cb44-666" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-667"><a href="#cb44-667" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_60_119)</span>
<span id="cb44-668"><a href="#cb44-668" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb44-669"><a href="#cb44-669" aria-hidden="true" tabindex="-1"></a>  staff_ratio_60_119<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_60_119,temp)</span>
<span id="cb44-670"><a href="#cb44-670" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-671"><a href="#cb44-671" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-672"><a href="#cb44-672" aria-hidden="true" tabindex="-1"></a><span class="co">#Second version with cutoffs 6 months later</span></span>
<span id="cb44-673"><a href="#cb44-673" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-674"><a href="#cb44-674" aria-hidden="true" tabindex="-1"></a>staff_ratio_66_125 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-675"><a href="#cb44-675" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_60_119)<span class="sc">%&gt;%</span></span>
<span id="cb44-676"><a href="#cb44-676" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">66</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-677"><a href="#cb44-677" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_60_119)</span>
<span id="cb44-678"><a href="#cb44-678" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-679"><a href="#cb44-679" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-680"><a href="#cb44-680" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">67</span><span class="sc">:</span><span class="dv">125</span>) {</span>
<span id="cb44-681"><a href="#cb44-681" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-682"><a href="#cb44-682" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_60_119)<span class="sc">%&gt;%</span></span>
<span id="cb44-683"><a href="#cb44-683" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-684"><a href="#cb44-684" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_60_119)</span>
<span id="cb44-685"><a href="#cb44-685" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb44-686"><a href="#cb44-686" aria-hidden="true" tabindex="-1"></a>  staff_ratio_66_125<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_66_125,temp)</span>
<span id="cb44-687"><a href="#cb44-687" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-688"><a href="#cb44-688" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-689"><a href="#cb44-689" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-690"><a href="#cb44-690" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-691"><a href="#cb44-691" aria-hidden="true" tabindex="-1"></a><span class="co">#Age 120+ (10+ years)</span></span>
<span id="cb44-692"><a href="#cb44-692" aria-hidden="true" tabindex="-1"></a><span class="do">####################</span></span>
<span id="cb44-693"><a href="#cb44-693" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-694"><a href="#cb44-694" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-695"><a href="#cb44-695" aria-hidden="true" tabindex="-1"></a>staff_ratio_120 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-696"><a href="#cb44-696" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_120)<span class="sc">%&gt;%</span></span>
<span id="cb44-697"><a href="#cb44-697" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">120</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-698"><a href="#cb44-698" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_120)</span>
<span id="cb44-699"><a href="#cb44-699" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-700"><a href="#cb44-700" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-701"><a href="#cb44-701" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">121</span><span class="sc">:</span><span class="dv">160</span>) {</span>
<span id="cb44-702"><a href="#cb44-702" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-703"><a href="#cb44-703" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_120)<span class="sc">%&gt;%</span></span>
<span id="cb44-704"><a href="#cb44-704" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-705"><a href="#cb44-705" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_120)</span>
<span id="cb44-706"><a href="#cb44-706" aria-hidden="true" tabindex="-1"></a>  staff_ratio_120<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_120,temp)</span>
<span id="cb44-707"><a href="#cb44-707" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-708"><a href="#cb44-708" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-709"><a href="#cb44-709" aria-hidden="true" tabindex="-1"></a><span class="co">#Second version with cutoffs 6 months later</span></span>
<span id="cb44-710"><a href="#cb44-710" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-711"><a href="#cb44-711" aria-hidden="true" tabindex="-1"></a>staff_ratio_126 <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-712"><a href="#cb44-712" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(state_str,month_120)<span class="sc">%&gt;%</span></span>
<span id="cb44-713"><a href="#cb44-713" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age_month=</span><span class="dv">126</span>)<span class="sc">%&gt;%</span></span>
<span id="cb44-714"><a href="#cb44-714" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_120)</span>
<span id="cb44-715"><a href="#cb44-715" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-716"><a href="#cb44-716" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a panel dataset</span></span>
<span id="cb44-717"><a href="#cb44-717" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (m <span class="cf">in</span> <span class="dv">127</span><span class="sc">:</span><span class="dv">160</span>) {</span>
<span id="cb44-718"><a href="#cb44-718" aria-hidden="true" tabindex="-1"></a>  temp <span class="ot">&lt;-</span> staff_ratio <span class="sc">%&gt;%</span></span>
<span id="cb44-719"><a href="#cb44-719" aria-hidden="true" tabindex="-1"></a>    <span class="fu">select</span>(state_str,month_120)<span class="sc">%&gt;%</span></span>
<span id="cb44-720"><a href="#cb44-720" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">age_month=</span> m)<span class="sc">%&gt;%</span></span>
<span id="cb44-721"><a href="#cb44-721" aria-hidden="true" tabindex="-1"></a>    <span class="fu">rename</span>(<span class="at">child_staff_ratio=</span>month_120)</span>
<span id="cb44-722"><a href="#cb44-722" aria-hidden="true" tabindex="-1"></a>  staff_ratio_126<span class="ot">=</span><span class="fu">rbind</span>(staff_ratio_126,temp)</span>
<span id="cb44-723"><a href="#cb44-723" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb44-724"><a href="#cb44-724" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-725"><a href="#cb44-725" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-726"><a href="#cb44-726" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-727"><a href="#cb44-727" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-728"><a href="#cb44-728" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-729"><a href="#cb44-729" aria-hidden="true" tabindex="-1"></a>panel_staff_ratio_6m_2007 <span class="ot">&lt;-</span> <span class="fu">rbind</span>(staff_ratio_0_14, staff_ratio_15_23, staff_ratio_24_32, staff_ratio_33_41, staff_ratio_42_53, </span>
<span id="cb44-730"><a href="#cb44-730" aria-hidden="true" tabindex="-1"></a>                                   staff_ratio_54_65, staff_ratio_66_125,staff_ratio_126)<span class="sc">%&gt;%</span></span>
<span id="cb44-731"><a href="#cb44-731" aria-hidden="true" tabindex="-1"></a>                                    <span class="co">#generate staff-to-child from child-to-staff ratio with 6 months lag</span></span>
<span id="cb44-732"><a href="#cb44-732" aria-hidden="true" tabindex="-1"></a>                                    <span class="fu">mutate</span>(<span class="at">staff_ratio_6m=</span><span class="dv">1</span><span class="sc">/</span>child_staff_ratio)<span class="sc">%&gt;%</span></span>
<span id="cb44-733"><a href="#cb44-733" aria-hidden="true" tabindex="-1"></a>                                    <span class="fu">select</span>(<span class="sc">-</span>child_staff_ratio)  </span>
<span id="cb44-734"><a href="#cb44-734" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-735"><a href="#cb44-735" aria-hidden="true" tabindex="-1"></a>panel_staff_ratio_2007 <span class="ot">&lt;-</span> <span class="fu">rbind</span>(staff_ratio_0_8, staff_ratio_9_17, staff_ratio_18_26, staff_ratio_27_35, staff_ratio_36_47, </span>
<span id="cb44-736"><a href="#cb44-736" aria-hidden="true" tabindex="-1"></a>                                staff_ratio_48_59, staff_ratio_60_119,staff_ratio_120)<span class="sc">%&gt;%</span></span>
<span id="cb44-737"><a href="#cb44-737" aria-hidden="true" tabindex="-1"></a>                                <span class="co">#generate staff-to-child from child-to-staff ratio</span></span>
<span id="cb44-738"><a href="#cb44-738" aria-hidden="true" tabindex="-1"></a>                                <span class="fu">mutate</span>(<span class="at">staff_ratio=</span><span class="dv">1</span><span class="sc">/</span>child_staff_ratio)<span class="sc">%&gt;%</span></span>
<span id="cb44-739"><a href="#cb44-739" aria-hidden="true" tabindex="-1"></a>                                <span class="fu">select</span>(<span class="sc">-</span>child_staff_ratio) <span class="sc">%&gt;%</span></span>
<span id="cb44-740"><a href="#cb44-740" aria-hidden="true" tabindex="-1"></a>                                <span class="fu">merge</span>(panel_staff_ratio_6m_2007)<span class="sc">%&gt;%</span></span>
<span id="cb44-741"><a href="#cb44-741" aria-hidden="true" tabindex="-1"></a>                                <span class="fu">mutate</span>(<span class="at">year=</span><span class="dv">2007</span>)</span>
<span id="cb44-742"><a href="#cb44-742" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-743"><a href="#cb44-743" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-744"><a href="#cb44-744" aria-hidden="true" tabindex="-1"></a><span class="co">#Delete all objects that start with staff_ratio again</span></span>
<span id="cb44-745"><a href="#cb44-745" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-746"><a href="#cb44-746" aria-hidden="true" tabindex="-1"></a><span class="co"># List all objects in the current environment</span></span>
<span id="cb44-747"><a href="#cb44-747" aria-hidden="true" tabindex="-1"></a>objects <span class="ot">&lt;-</span> <span class="fu">ls</span>()</span>
<span id="cb44-748"><a href="#cb44-748" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-749"><a href="#cb44-749" aria-hidden="true" tabindex="-1"></a><span class="co"># Identify objects starting with "staff_ratio"</span></span>
<span id="cb44-750"><a href="#cb44-750" aria-hidden="true" tabindex="-1"></a>objects_to_delete <span class="ot">&lt;-</span> objects[<span class="fu">grep</span>(<span class="st">"^staff_ratio"</span>, objects)]</span>
<span id="cb44-751"><a href="#cb44-751" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-752"><a href="#cb44-752" aria-hidden="true" tabindex="-1"></a><span class="co"># Delete objects starting with "staff_ratio"</span></span>
<span id="cb44-753"><a href="#cb44-753" aria-hidden="true" tabindex="-1"></a><span class="fu">rm</span>(<span class="at">list =</span> objects_to_delete)</span>
<span id="cb44-754"><a href="#cb44-754" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-755"><a href="#cb44-755" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb44-756"><a href="#cb44-756" aria-hidden="true" tabindex="-1"></a><span class="co">#Merge all  panels with ratios together</span></span>
<span id="cb44-757"><a href="#cb44-757" aria-hidden="true" tabindex="-1"></a>staff_ratio_panel <span class="ot">&lt;-</span> <span class="fu">rbind</span>(panel_staff_ratio_1997, panel_staff_ratio_2002, panel_staff_ratio_2007)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
</section>
<section id="assembling-a-panel-of-cds-mothers" class="level1">
<h1>Assembling a Panel of CDS Mothers</h1>
<section id="making-a-panel-with-fertility-history" class="level2">
<h2 class="anchored" data-anchor-id="making-a-panel-with-fertility-history">Making a Panel with Fertility History</h2>
<p>We start by loading the childbirth history file, which we will use to identify mothers and arrange their fertility history into a panel dataset. It will be useful to know the following mapping between variable names and variables:</p>
<table class="caption-top table">
<thead>
<tr class="header">
<th style="text-align: left;">Vnum</th>
<th style="text-align: left;">Vname</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">CAH3</td>
<td style="text-align: left;">intnum68</td>
</tr>
<tr class="even">
<td style="text-align: left;">CAH4</td>
<td style="text-align: left;">pernum</td>
</tr>
<tr class="odd">
<td style="text-align: left;">CAH5</td>
<td style="text-align: left;">sex</td>
</tr>
<tr class="even">
<td style="text-align: left;">CAH6</td>
<td style="text-align: left;">parent month of birth</td>
</tr>
<tr class="odd">
<td style="text-align: left;">CAH7</td>
<td style="text-align: left;">parent year of birth</td>
</tr>
<tr class="even">
<td style="text-align: left;">CAH8</td>
<td style="text-align: left;">marital status when born</td>
</tr>
<tr class="odd">
<td style="text-align: left;">CAH9</td>
<td style="text-align: left;">birth order</td>
</tr>
<tr class="even">
<td style="text-align: left;">CAH10</td>
<td style="text-align: left;">child intnum</td>
</tr>
<tr class="odd">
<td style="text-align: left;">CAH11</td>
<td style="text-align: left;">child pernum</td>
</tr>
<tr class="even">
<td style="text-align: left;">CAH12</td>
<td style="text-align: left;">sex of child</td>
</tr>
<tr class="odd">
<td style="text-align: left;">CAH13</td>
<td style="text-align: left;">child month of birth</td>
</tr>
<tr class="even">
<td style="text-align: left;">CAH15</td>
<td style="text-align: left;">child year of birth</td>
</tr>
<tr class="odd">
<td style="text-align: left;">CAH108</td>
<td style="text-align: left;">number of birth records</td>
</tr>
</tbody>
</table>
<p>The chunk below loads these data and applies some sample restrictions: - Drop women without recorded births - Drop women with missing birth year information - Drop women with missing information in their childbirth history - Keep only women whose children appear in the CDS</p>
<p>First, we use one of the cleaned CDS files to get a file with ID numbners of all CDS children.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb45"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb45-1"><a href="#cb45-1" aria-hidden="true" tabindex="-1"></a><span class="co"># get an index of CDS children</span></span>
<span id="cb45-2"><a href="#cb45-2" aria-hidden="true" tabindex="-1"></a>KID <span class="ot">&lt;-</span> assessment_panel <span class="sc">%&gt;%</span></span>
<span id="cb45-3"><a href="#cb45-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(KID) <span class="sc">%&gt;%</span></span>
<span id="cb45-4"><a href="#cb45-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">unique</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Next, we load the childbirth record for women in the PSID and apply some sample restrictions.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb46"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb46-1"><a href="#cb46-1" aria-hidden="true" tabindex="-1"></a>child_record <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="st">"../../../data/data_PSID/main/childbirth/Childbirth.csv"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb46-2"><a href="#cb46-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">X =</span> <span class="cn">NULL</span>) <span class="sc">%&gt;%</span> <span class="co">#&lt;- load childbirth file</span></span>
<span id="cb46-3"><a href="#cb46-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(CAH5 <span class="sc">==</span> <span class="dv">2</span>) <span class="sc">%&gt;%</span> <span class="co"># keep only women</span></span>
<span id="cb46-4"><a href="#cb46-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(CAH10 <span class="sc">!=</span> <span class="dv">0</span>) <span class="sc">%&gt;%</span> <span class="co"># drop women who have no children according to this file</span></span>
<span id="cb46-5"><a href="#cb46-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(CAH7 <span class="sc">!=</span> <span class="dv">9998</span>) <span class="sc">%&gt;%</span> <span class="co"># drop women with missing birth year info</span></span>
<span id="cb46-6"><a href="#cb46-6" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">MID =</span> CAH3 <span class="sc">*</span> <span class="dv">1000</span> <span class="sc">+</span> CAH4, <span class="at">KID =</span> CAH10 <span class="sc">*</span> <span class="dv">1000</span> <span class="sc">+</span> CAH11) <span class="sc">%&gt;%</span></span>
<span id="cb46-7"><a href="#cb46-7" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(MID) <span class="sc">%&gt;%</span></span>
<span id="cb46-8"><a href="#cb46-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(<span class="sc">!</span><span class="fu">any</span>(CAH10 <span class="sc">==</span> <span class="dv">9999</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>We use this childbirth record to first create a data frame with the IDs of all CDS mothers.</p>
<p>Then, we use that file to produce a full childbirth history file with just CDS mothers.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb47"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb47-1"><a href="#cb47-1" aria-hidden="true" tabindex="-1"></a>mother_index <span class="ot">&lt;-</span> child_record <span class="sc">%&gt;%</span></span>
<span id="cb47-2"><a href="#cb47-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(MID, KID) <span class="sc">%&gt;%</span></span>
<span id="cb47-3"><a href="#cb47-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">inner_join</span>(KID) <span class="sc">%&gt;%</span></span>
<span id="cb47-4"><a href="#cb47-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(MID) <span class="sc">%&gt;%</span></span>
<span id="cb47-5"><a href="#cb47-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">unique</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Joining with `by = join_by(KID)`</code></pre>
</div>
<div class="sourceCode cell-code" id="cb49"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb49-1"><a href="#cb49-1" aria-hidden="true" tabindex="-1"></a>C <span class="ot">&lt;-</span> child_record <span class="sc">%&gt;%</span> <span class="co">#&lt;- this matches the sample from before. All good.</span></span>
<span id="cb49-2"><a href="#cb49-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">inner_join</span>(mother_index)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Joining with `by = join_by(MID)`</code></pre>
</div>
</div>
<p>We want a panel dataset that begins when each mother turns 18 and ends in 2017. Each individual-year observation has the number of dependent children, the age of the youngest child, the number of children between 0 and 5, and the number of children between 6 and 12.</p>
<p>The function below does this assuming that some dataframe <code>d</code> contains the childbirth data for just one mother:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb51"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb51-1"><a href="#cb51-1" aria-hidden="true" tabindex="-1"></a>MakePanel <span class="ot">&lt;-</span> <span class="cf">function</span>(d) {</span>
<span id="cb51-2"><a href="#cb51-2" aria-hidden="true" tabindex="-1"></a>  year <span class="ot">&lt;-</span> (d<span class="sc">$</span>CAH7[<span class="dv">1</span>] <span class="sc">+</span> <span class="dv">16</span>)<span class="sc">:</span><span class="dv">2017</span></span>
<span id="cb51-3"><a href="#cb51-3" aria-hidden="true" tabindex="-1"></a>  n_y <span class="ot">&lt;-</span> <span class="fu">length</span>(year)</span>
<span id="cb51-4"><a href="#cb51-4" aria-hidden="true" tabindex="-1"></a>  knum <span class="ot">&lt;-</span> d<span class="sc">$</span>CAH108[<span class="dv">1</span>]</span>
<span id="cb51-5"><a href="#cb51-5" aria-hidden="true" tabindex="-1"></a>  age_youngest <span class="ot">&lt;-</span> <span class="fu">integer</span>(n_y) <span class="sc">-</span> <span class="dv">1</span></span>
<span id="cb51-6"><a href="#cb51-6" aria-hidden="true" tabindex="-1"></a>  age_oldest <span class="ot">&lt;-</span> <span class="fu">integer</span>(n_y) <span class="sc">+</span> <span class="cn">Inf</span></span>
<span id="cb51-7"><a href="#cb51-7" aria-hidden="true" tabindex="-1"></a>  num_0_5 <span class="ot">&lt;-</span> <span class="fu">integer</span>(n_y)</span>
<span id="cb51-8"><a href="#cb51-8" aria-hidden="true" tabindex="-1"></a>  num_6_12 <span class="ot">&lt;-</span> <span class="fu">integer</span>(n_y)</span>
<span id="cb51-9"><a href="#cb51-9" aria-hidden="true" tabindex="-1"></a>  num_child <span class="ot">&lt;-</span> <span class="fu">integer</span>(n_y)</span>
<span id="cb51-10"><a href="#cb51-10" aria-hidden="true" tabindex="-1"></a>  m_age <span class="ot">&lt;-</span> year <span class="sc">-</span> d<span class="sc">$</span>CAH7[<span class="dv">1</span>]</span>
<span id="cb51-11"><a href="#cb51-11" aria-hidden="true" tabindex="-1"></a>  <span class="cf">for</span> (i <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span><span class="fu">length</span>(year)) {</span>
<span id="cb51-12"><a href="#cb51-12" aria-hidden="true" tabindex="-1"></a>    ay <span class="ot">&lt;-</span> <span class="cn">Inf</span></span>
<span id="cb51-13"><a href="#cb51-13" aria-hidden="true" tabindex="-1"></a>    ao <span class="ot">&lt;-</span> <span class="sc">-</span><span class="dv">1</span></span>
<span id="cb51-14"><a href="#cb51-14" aria-hidden="true" tabindex="-1"></a>    a5 <span class="ot">&lt;-</span> <span class="dv">0</span></span>
<span id="cb51-15"><a href="#cb51-15" aria-hidden="true" tabindex="-1"></a>    a6 <span class="ot">&lt;-</span> <span class="dv">0</span></span>
<span id="cb51-16"><a href="#cb51-16" aria-hidden="true" tabindex="-1"></a>    <span class="cf">for</span> (k <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span><span class="fu">nrow</span>(d)) {</span>
<span id="cb51-17"><a href="#cb51-17" aria-hidden="true" tabindex="-1"></a>      agek <span class="ot">&lt;-</span> year[i] <span class="sc">-</span> d<span class="sc">$</span>CAH15[k]</span>
<span id="cb51-18"><a href="#cb51-18" aria-hidden="true" tabindex="-1"></a>      <span class="cf">if</span> (agek <span class="sc">&gt;=</span> <span class="dv">0</span> <span class="sc">&amp;&amp;</span> agek <span class="sc">&lt;=</span> <span class="dv">18</span>) {</span>
<span id="cb51-19"><a href="#cb51-19" aria-hidden="true" tabindex="-1"></a>        ay <span class="ot">&lt;-</span> <span class="fu">min</span>(ay, agek)</span>
<span id="cb51-20"><a href="#cb51-20" aria-hidden="true" tabindex="-1"></a>        ao <span class="ot">&lt;-</span> <span class="fu">max</span>(ao, agek)</span>
<span id="cb51-21"><a href="#cb51-21" aria-hidden="true" tabindex="-1"></a>        num_child[i] <span class="ot">&lt;-</span> num_child[i] <span class="sc">+</span> <span class="dv">1</span></span>
<span id="cb51-22"><a href="#cb51-22" aria-hidden="true" tabindex="-1"></a>      }</span>
<span id="cb51-23"><a href="#cb51-23" aria-hidden="true" tabindex="-1"></a>      <span class="cf">if</span> (agek <span class="sc">&gt;=</span> <span class="dv">0</span> <span class="sc">&amp;&amp;</span> agek <span class="sc">&lt;=</span> <span class="dv">5</span>) {</span>
<span id="cb51-24"><a href="#cb51-24" aria-hidden="true" tabindex="-1"></a>        a5 <span class="ot">&lt;-</span> a5 <span class="sc">+</span> <span class="dv">1</span></span>
<span id="cb51-25"><a href="#cb51-25" aria-hidden="true" tabindex="-1"></a>      }</span>
<span id="cb51-26"><a href="#cb51-26" aria-hidden="true" tabindex="-1"></a>      <span class="cf">if</span> (agek <span class="sc">&gt;</span> <span class="dv">5</span> <span class="sc">&amp;&amp;</span> agek <span class="sc">&lt;=</span> <span class="dv">12</span>) {</span>
<span id="cb51-27"><a href="#cb51-27" aria-hidden="true" tabindex="-1"></a>        a6 <span class="ot">&lt;-</span> a6 <span class="sc">+</span> <span class="dv">1</span></span>
<span id="cb51-28"><a href="#cb51-28" aria-hidden="true" tabindex="-1"></a>      }</span>
<span id="cb51-29"><a href="#cb51-29" aria-hidden="true" tabindex="-1"></a>    }</span>
<span id="cb51-30"><a href="#cb51-30" aria-hidden="true" tabindex="-1"></a>    age_youngest[i] <span class="ot">&lt;-</span> ay</span>
<span id="cb51-31"><a href="#cb51-31" aria-hidden="true" tabindex="-1"></a>    age_oldest[i] <span class="ot">&lt;-</span> ao</span>
<span id="cb51-32"><a href="#cb51-32" aria-hidden="true" tabindex="-1"></a>    num_0_5[i] <span class="ot">&lt;-</span> a5</span>
<span id="cb51-33"><a href="#cb51-33" aria-hidden="true" tabindex="-1"></a>    num_6_12[i] <span class="ot">&lt;-</span> a6</span>
<span id="cb51-34"><a href="#cb51-34" aria-hidden="true" tabindex="-1"></a>  }</span>
<span id="cb51-35"><a href="#cb51-35" aria-hidden="true" tabindex="-1"></a>  <span class="fu">data.frame</span>(<span class="at">MID =</span> d<span class="sc">$</span>MID[<span class="dv">1</span>], <span class="at">m_age =</span> m_age, <span class="at">year =</span> year, <span class="at">knum =</span> knum, <span class="at">num_child =</span> num_child, <span class="at">age_youngest =</span> age_youngest, <span class="at">age_oldest =</span> age_oldest, <span class="at">num_0_5 =</span> num_0_5, <span class="at">num_6_12 =</span> num_6_12, <span class="at">y_first =</span> d<span class="sc">$</span>CAH15[<span class="dv">1</span>])</span>
<span id="cb51-36"><a href="#cb51-36" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>The chunk below applies the function for each mother (defined by their ID number <code>MID</code>) which results in a panel dataset. In order to speed up analysis, we also drop observations that we know will be too early for the CDS (everyone with first births before 1960).</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb52"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb52-1"><a href="#cb52-1" aria-hidden="true" tabindex="-1"></a>mother_panel <span class="ot">&lt;-</span> C <span class="sc">%&gt;%</span></span>
<span id="cb52-2"><a href="#cb52-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(MID) <span class="sc">%&gt;%</span></span>
<span id="cb52-3"><a href="#cb52-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">do</span>(<span class="fu">MakePanel</span>(.)) <span class="sc">%&gt;%</span></span>
<span id="cb52-4"><a href="#cb52-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(y_first <span class="sc">&gt;=</span> <span class="dv">1960</span>) <span class="sc">%&gt;%</span></span>
<span id="cb52-5"><a href="#cb52-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">left_join</span>(passage_comprehension) <span class="co"># Add mother's cognitive score</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Joining with `by = join_by(MID)`</code></pre>
</div>
</div>
</section>
<section id="merge-in-state-identifiers-and-childcare-expenditures" class="level2">
<h2 class="anchored" data-anchor-id="merge-in-state-identifiers-and-childcare-expenditures">Merge in State Identifiers and Childcare Expenditures</h2>
<p>We start by merging this panel with the Individual Cross-Year File, which maps an (ID,year) combination with an interview number and sequence number (which allows us to link with state codes and household child care expenditures)</p>
<p>This chunk loads the individual file and creates the ID number:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb54"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb54-1"><a href="#cb54-1" aria-hidden="true" tabindex="-1"></a>Ind <span class="ot">&lt;-</span> identifiers_panel <span class="sc">%&gt;%</span></span>
<span id="cb54-2"><a href="#cb54-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">MID =</span> intnum68 <span class="sc">*</span> <span class="dv">1000</span> <span class="sc">+</span> pernum, <span class="at">mar_stat =</span> mpair <span class="sc">&gt;</span> <span class="dv">0</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Since we would like to see marital status in some non-interview years, we use the following year’s marital status:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb55"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb55-1"><a href="#cb55-1" aria-hidden="true" tabindex="-1"></a>Ind <span class="ot">&lt;-</span> Ind <span class="sc">%&gt;%</span></span>
<span id="cb55-2"><a href="#cb55-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year <span class="sc">&gt;=</span> <span class="dv">1999</span>) <span class="sc">%&gt;%</span></span>
<span id="cb55-3"><a href="#cb55-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> year <span class="sc">-</span> <span class="dv">1</span>) <span class="sc">%&gt;%</span></span>
<span id="cb55-4"><a href="#cb55-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rbind</span>(Ind)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>This method of imputation ensures that we only fill in missing data from non-interview years.</p>
<p>One thing that will be useful throughout is a panel with the mother’s ID linked to their interview and calendar year. Some variables from the main interview refer to the previous year and things can get messy, so we use this file to keep things consistent.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb56"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb56-1"><a href="#cb56-1" aria-hidden="true" tabindex="-1"></a><span class="co"># this will be useful throughout: create a dataframe that maps mothers to their interview number and sequence number</span></span>
<span id="cb56-2"><a href="#cb56-2" aria-hidden="true" tabindex="-1"></a>D_Ind <span class="ot">&lt;-</span> mother_panel <span class="sc">%&gt;%</span></span>
<span id="cb56-3"><a href="#cb56-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">inner_join</span>(Ind)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Joining with `by = join_by(MID, year)`</code></pre>
</div>
</div>
<p>Next we merge the panel of state codes with the cross-year individual file. We then merge that file with a state code cross-walk so that we can link the PSID’s state code with FIPS and SOI. We also merge, based on the household interview number and year, annual household expenditures on child care (cleaned in a previous section).</p>
<p>Finally, this file is merged with the panel of mothers we just created, using years before and after to fill in missing state observations.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb58"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb58-1"><a href="#cb58-1" aria-hidden="true" tabindex="-1"></a>main_childcare <span class="ot">&lt;-</span> main_childcare <span class="sc">%&gt;%</span></span>
<span id="cb58-2"><a href="#cb58-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">inner_join</span>(D_Ind) <span class="sc">%&gt;%</span> <span class="co">#&lt;- merge to mothers through the panel file</span></span>
<span id="cb58-3"><a href="#cb58-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> year <span class="sc">-</span> <span class="dv">1</span>) <span class="sc">%&gt;%</span> <span class="co">#&lt;- convert survey year to lag year</span></span>
<span id="cb58-4"><a href="#cb58-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(MID, year, childcare_exp)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Joining with `by = join_by(year, intnum)`</code></pre>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb60"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb60-1"><a href="#cb60-1" aria-hidden="true" tabindex="-1"></a>mother_panel <span class="ot">&lt;-</span> main_state <span class="sc">%&gt;%</span></span>
<span id="cb60-2"><a href="#cb60-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">right_join</span>(Ind) <span class="sc">%&gt;%</span> <span class="co">#&lt;- merge with Individual file</span></span>
<span id="cb60-3"><a href="#cb60-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">right_join</span>(mother_panel) <span class="sc">%&gt;%</span> <span class="co">#&lt;- merge with the panel we created (keeping all years)</span></span>
<span id="cb60-4"><a href="#cb60-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">arrange</span>(MID, year) <span class="sc">%&gt;%</span></span>
<span id="cb60-5"><a href="#cb60-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(MID) <span class="sc">%&gt;%</span></span>
<span id="cb60-6"><a href="#cb60-6" aria-hidden="true" tabindex="-1"></a>  <span class="fu">fill</span>(state, <span class="at">.direction =</span> <span class="st">"downup"</span>) <span class="sc">%&gt;%</span> <span class="co">#&lt;- fill in missing observations</span></span>
<span id="cb60-7"><a href="#cb60-7" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(state_codes) <span class="sc">%&gt;%</span> <span class="co">#&lt;- merge in the cross-walk with FIPS codes and SOI codes</span></span>
<span id="cb60-8"><a href="#cb60-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">left_join</span>(main_childcare) <span class="co">#&lt;= use only the main file to link</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Joining with `by = join_by(intnum, year)`
Joining with `by = join_by(year, MID)`
Joining with `by = join_by(year, MID)`</code></pre>
</div>
</div>
</section>
<section id="identify-and-merge-in-spouses-fathers" class="level2">
<h2 class="anchored" data-anchor-id="identify-and-merge-in-spouses-fathers">Identify and Merge in Spouses (“Fathers”)</h2>
<p>The next step is to identify spouses for each mother in each year. Spouses are linked by the <code>mpair</code> variable which is unique within a household interview. We identify partners by:</p>
<ol type="1">
<li>Merging the individual file with the triple (<code>MID</code>,<code>year</code>,<code>m_age</code>) from the panel, keeping all observations from the individual file.</li>
<li>Partners are identified by the fact that they are not successfully matched in this merge, meaning that <code>m_age</code> will be missing. We keep those observations and rename the variables in order to merge them once more with the panel of mothers.</li>
</ol>
<div class="cell">
<div class="sourceCode cell-code" id="cb62"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb62-1"><a href="#cb62-1" aria-hidden="true" tabindex="-1"></a>mother_panel <span class="ot">&lt;-</span> mother_panel <span class="sc">%&gt;%</span></span>
<span id="cb62-2"><a href="#cb62-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(MID, year, m_age) <span class="sc">%&gt;%</span></span>
<span id="cb62-3"><a href="#cb62-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">right_join</span>(Ind) <span class="sc">%&gt;%</span> <span class="co">#&lt;- merge with individual file, keep all observations from Ind</span></span>
<span id="cb62-4"><a href="#cb62-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(<span class="fu">is.na</span>(m_age)) <span class="sc">%&gt;%</span> <span class="co">#&lt;- identify spouses by missing info from the merge</span></span>
<span id="cb62-5"><a href="#cb62-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">FID =</span> MID, <span class="at">snF =</span> sn) <span class="sc">%&gt;%</span> <span class="co">#&lt;- rename variables for merge</span></span>
<span id="cb62-6"><a href="#cb62-6" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(mpair <span class="sc">&gt;</span> <span class="dv">0</span>) <span class="sc">%&gt;%</span> <span class="co">#&lt;- only keep individuals who are not mothers but who are in a relationship in the same household</span></span>
<span id="cb62-7"><a href="#cb62-7" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(FID, year, intnum, mpair, snF) <span class="sc">%&gt;%</span></span>
<span id="cb62-8"><a href="#cb62-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">right_join</span>(mother_panel) <span class="sc">%&gt;%</span> <span class="co">#&lt;- do the merge</span></span>
<span id="cb62-9"><a href="#cb62-9" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">snF =</span> <span class="fu">replace_na</span>(snF, <span class="sc">-</span><span class="dv">1</span>)) <span class="co">#&lt;- replace missing values.</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Joining with `by = join_by(MID, year)`
Joining with `by = join_by(year, intnum, mpair)`</code></pre>
</div>
</div>
<p>Create distance to parents files in 1988 using ID’s.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb64"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb64-1"><a href="#cb64-1" aria-hidden="true" tabindex="-1"></a><span class="co">#Load miles to parents in 1988</span></span>
<span id="cb64-2"><a href="#cb64-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb64-3"><a href="#cb64-3" aria-hidden="true" tabindex="-1"></a>d <span class="ot">&lt;-</span> parent_distance <span class="sc">%&gt;%</span></span>
<span id="cb64-4"><a href="#cb64-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum88=</span>intnum)</span>
<span id="cb64-5"><a href="#cb64-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb64-6"><a href="#cb64-6" aria-hidden="true" tabindex="-1"></a><span class="co">#Match miles to parents in 1988 by family intnum for mothers and fathers</span></span>
<span id="cb64-7"><a href="#cb64-7" aria-hidden="true" tabindex="-1"></a>id <span class="ot">&lt;-</span> Ind  <span class="sc">%&gt;%</span> </span>
<span id="cb64-8"><a href="#cb64-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year<span class="sc">==</span><span class="dv">1988</span>) <span class="sc">%&gt;%</span></span>
<span id="cb64-9"><a href="#cb64-9" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">id =</span> MID)<span class="sc">%&gt;%</span></span>
<span id="cb64-10"><a href="#cb64-10" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(id, sn, intnum)<span class="sc">%&gt;%</span></span>
<span id="cb64-11"><a href="#cb64-11" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">intnum88=</span>intnum)</span>
<span id="cb64-12"><a href="#cb64-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb64-13"><a href="#cb64-13" aria-hidden="true" tabindex="-1"></a><span class="co"># mothers: use mid from the main sample, assign distance based on family intnum and sn</span></span>
<span id="cb64-14"><a href="#cb64-14" aria-hidden="true" tabindex="-1"></a>mother_distance <span class="ot">&lt;-</span> mother_panel <span class="sc">%&gt;%</span></span>
<span id="cb64-15"><a href="#cb64-15" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(MID) <span class="sc">%&gt;%</span></span>
<span id="cb64-16"><a href="#cb64-16" aria-hidden="true" tabindex="-1"></a>  <span class="fu">unique</span>() <span class="sc">%&gt;%</span></span>
<span id="cb64-17"><a href="#cb64-17" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(id,<span class="at">by.x=</span><span class="st">"MID"</span>,<span class="at">by.y=</span><span class="st">"id"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb64-18"><a href="#cb64-18" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(d) <span class="sc">%&gt;%</span></span>
<span id="cb64-19"><a href="#cb64-19" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">m_parents_hundred =</span> <span class="fu">case_when</span>(sn<span class="sc">==</span><span class="dv">1</span> <span class="sc">~</span> head_hundred_miles,sn<span class="sc">==</span><span class="dv">2</span> <span class="sc">~</span> sp_hundred_miles),</span>
<span id="cb64-20"><a href="#cb64-20" aria-hidden="true" tabindex="-1"></a>         <span class="at">m_parents_ten =</span> <span class="fu">case_when</span>(sn<span class="sc">==</span><span class="dv">1</span> <span class="sc">~</span> head_ten_miles,sn<span class="sc">==</span><span class="dv">2</span> <span class="sc">~</span> sp_ten_miles)) <span class="sc">%&gt;%</span></span>
<span id="cb64-21"><a href="#cb64-21" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(MID,m_parents_hundred,m_parents_ten)</span>
<span id="cb64-22"><a href="#cb64-22" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb64-23"><a href="#cb64-23" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb64-24"><a href="#cb64-24" aria-hidden="true" tabindex="-1"></a><span class="co"># fathers: use fid from the main sample, assign distance based on family intnum and sn</span></span>
<span id="cb64-25"><a href="#cb64-25" aria-hidden="true" tabindex="-1"></a>father_distance <span class="ot">&lt;-</span> mother_panel <span class="sc">%&gt;%</span></span>
<span id="cb64-26"><a href="#cb64-26" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(FID) <span class="sc">%&gt;%</span></span>
<span id="cb64-27"><a href="#cb64-27" aria-hidden="true" tabindex="-1"></a>  <span class="fu">drop_na</span>() <span class="sc">%&gt;%</span></span>
<span id="cb64-28"><a href="#cb64-28" aria-hidden="true" tabindex="-1"></a>  <span class="fu">unique</span>() <span class="sc">%&gt;%</span></span>
<span id="cb64-29"><a href="#cb64-29" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(id,<span class="at">by.x=</span><span class="st">"FID"</span>,<span class="at">by.y=</span><span class="st">"id"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb64-30"><a href="#cb64-30" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(d) <span class="sc">%&gt;%</span></span>
<span id="cb64-31"><a href="#cb64-31" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">f_parents_hundred =</span> <span class="fu">case_when</span>(sn<span class="sc">==</span><span class="dv">1</span> <span class="sc">~</span> head_hundred_miles,sn<span class="sc">==</span><span class="dv">2</span> <span class="sc">~</span> sp_hundred_miles),</span>
<span id="cb64-32"><a href="#cb64-32" aria-hidden="true" tabindex="-1"></a>         <span class="at">f_parents_ten =</span> <span class="fu">case_when</span>(sn<span class="sc">==</span><span class="dv">1</span> <span class="sc">~</span> head_ten_miles,sn<span class="sc">==</span><span class="dv">2</span> <span class="sc">~</span> sp_ten_miles)) <span class="sc">%&gt;%</span></span>
<span id="cb64-33"><a href="#cb64-33" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(FID,f_parents_hundred,f_parents_ten)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="merge-in-spouse-birth-year-and-marriage-summary-variables" class="level2">
<h2 class="anchored" data-anchor-id="merge-in-spouse-birth-year-and-marriage-summary-variables">Merge in Spouse Birth Year and Marriage Summary Variables</h2>
<p>The <em>Marriage History File</em> is prepared by the PSID and contains a record of each marriage in the PSID. We use this file to determine which individuals have ever been married, to filter out individuals with missing marriage information, and to identify the birth year of spouses.</p>
<p>First we load the marriage file and create an “ever” married summary variable. We finish by merging this file with the main panel (based on MID)</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb65"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb65-1"><a href="#cb65-1" aria-hidden="true" tabindex="-1"></a><span class="co"># #  ---- load marriage info and create some summary variables</span></span>
<span id="cb65-2"><a href="#cb65-2" aria-hidden="true" tabindex="-1"></a>M <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="st">"../../../data/data_PSID/main/marriage/Marriage.csv"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb65-3"><a href="#cb65-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">X =</span> <span class="cn">NULL</span>) <span class="sc">%&gt;%</span></span>
<span id="cb65-4"><a href="#cb65-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">MID =</span> ID1) <span class="sc">%&gt;%</span> <span class="co">#&lt;- we rename to MID in preparation for a first merge with sample mothers</span></span>
<span id="cb65-5"><a href="#cb65-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">ybirth =</span> MH6) <span class="sc">%&gt;%</span></span>
<span id="cb65-6"><a href="#cb65-6" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(ybirth <span class="sc">&lt;</span> <span class="dv">9998</span>) <span class="sc">%&gt;%</span> <span class="co">#&lt;- drop individuals with missing birth info</span></span>
<span id="cb65-7"><a href="#cb65-7" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">ymar =</span> MH11) <span class="sc">%&gt;%</span></span>
<span id="cb65-8"><a href="#cb65-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(ymar <span class="sc">!=</span> <span class="dv">9998</span>) <span class="sc">%&gt;%</span> <span class="co">#&lt;- remove individuals without marriage info</span></span>
<span id="cb65-9"><a href="#cb65-9" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">record =</span> ymar <span class="sc">&lt;</span> <span class="dv">9999</span>) <span class="sc">%&gt;%</span> <span class="co">#&lt;- ymar==9999 indicates never married</span></span>
<span id="cb65-10"><a href="#cb65-10" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(MID) <span class="sc">%&gt;%</span></span>
<span id="cb65-11"><a href="#cb65-11" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarise</span>(<span class="at">ever_married =</span> <span class="fu">sum</span>(record) <span class="sc">&gt;</span> <span class="dv">0</span>, <span class="at">ybirth =</span> ybirth[<span class="dv">1</span>])</span>
<span id="cb65-12"><a href="#cb65-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb65-13"><a href="#cb65-13" aria-hidden="true" tabindex="-1"></a>mother_panel <span class="ot">&lt;-</span> M <span class="sc">%&gt;%</span></span>
<span id="cb65-14"><a href="#cb65-14" aria-hidden="true" tabindex="-1"></a>  <span class="fu">inner_join</span>(mother_panel)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Joining with `by = join_by(MID)`</code></pre>
</div>
</div>
<p>We also use this file to merge with FID for each spouse to deduce the spouse’s age. This means we don’t have the spouse’s age for cohabiting couples. We use the triple <em>year</em>, <em>intnum</em> and <em>mpair</em> to match women with their spouses. To do this, we first create an individual index file of people that are <em>not</em> women in the sample. This is the potential pool of fathers that we use for the merge.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb67"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb67-1"><a href="#cb67-1" aria-hidden="true" tabindex="-1"></a>mother_panel <span class="ot">&lt;-</span> D_Ind <span class="sc">%&gt;%</span></span>
<span id="cb67-2"><a href="#cb67-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(MID, year, m_age) <span class="sc">%&gt;%</span></span>
<span id="cb67-3"><a href="#cb67-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">right_join</span>(Ind) <span class="sc">%&gt;%</span></span>
<span id="cb67-4"><a href="#cb67-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(<span class="fu">is.na</span>(m_age)) <span class="sc">%&gt;%</span> <span class="co">#&lt;- pick out individuals from the merge who were *not* matched</span></span>
<span id="cb67-5"><a href="#cb67-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">FID =</span> MID, <span class="at">snF =</span> sn) <span class="sc">%&gt;%</span></span>
<span id="cb67-6"><a href="#cb67-6" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(<span class="fu">c</span>(<span class="st">"FID"</span>, <span class="st">"year"</span>, <span class="st">"intnum"</span>, <span class="st">"mpair"</span>, <span class="st">"snF"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb67-7"><a href="#cb67-7" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(mpair <span class="sc">&gt;</span> <span class="dv">0</span>) <span class="sc">%&gt;%</span></span>
<span id="cb67-8"><a href="#cb67-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">right_join</span>(mother_panel)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Joining with `by = join_by(MID, year)`
Joining with `by = join_by(FID, year, intnum, mpair, snF)`</code></pre>
</div>
<div class="sourceCode cell-code" id="cb69"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb69-1"><a href="#cb69-1" aria-hidden="true" tabindex="-1"></a>mother_panel <span class="ot">&lt;-</span> M <span class="sc">%&gt;%</span></span>
<span id="cb69-2"><a href="#cb69-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">FID =</span> MID, <span class="at">ybirthF =</span> ybirth) <span class="sc">%&gt;%</span></span>
<span id="cb69-3"><a href="#cb69-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">right_join</span>(mother_panel) <span class="sc">%&gt;%</span></span>
<span id="cb69-4"><a href="#cb69-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">f_age =</span> year <span class="sc">-</span> ybirthF)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Joining with `by = join_by(FID, ever_married)`</code></pre>
</div>
</div>
</section>
<section id="merge-in-mothers-race-education-and-cpi-external" class="level2">
<h2 class="anchored" data-anchor-id="merge-in-mothers-race-education-and-cpi-external">Merge in Mother’s Race, Education, and CPI (external)</h2>
<p>Race and education are previously cleaned summary variables. We drop mothers from the sample with missing information on education and race.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb71"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb71-1"><a href="#cb71-1" aria-hidden="true" tabindex="-1"></a><span class="co"># normalized to year 2002</span></span>
<span id="cb71-2"><a href="#cb71-2" aria-hidden="true" tabindex="-1"></a>cpi <span class="ot">=</span> <span class="fu">read.csv</span>(<span class="st">"../../../data/data_PSID/CPI-U.csv"</span>) <span class="sc">%&gt;%</span></span>
<span id="cb71-3"><a href="#cb71-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">year =</span> YEAR) <span class="sc">%&gt;%</span></span>
<span id="cb71-4"><a href="#cb71-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">CPIU =</span> CPIU<span class="sc">/</span>CPIU[<span class="dv">56</span>])</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Then we merge them into the main file.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb72"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb72-1"><a href="#cb72-1" aria-hidden="true" tabindex="-1"></a>mother_panel <span class="ot">&lt;-</span> mother_panel <span class="sc">%&gt;%</span> <span class="co">#&lt;- drop if mother has missing race or education info</span></span>
<span id="cb72-2"><a href="#cb72-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">inner_join</span>(education, <span class="at">by =</span> <span class="fu">c</span>(<span class="st">"MID"</span> <span class="ot">=</span> <span class="st">"ID"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb72-3"><a href="#cb72-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">m_ed =</span> ed) <span class="sc">%&gt;%</span></span>
<span id="cb72-4"><a href="#cb72-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">left_join</span>(education, <span class="at">by =</span> <span class="fu">c</span>(<span class="st">"FID"</span> <span class="ot">=</span> <span class="st">"ID"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb72-5"><a href="#cb72-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">f_ed =</span> ed) <span class="sc">%&gt;%</span></span>
<span id="cb72-6"><a href="#cb72-6" aria-hidden="true" tabindex="-1"></a>  <span class="fu">left_join</span>(race, <span class="at">by =</span> <span class="fu">c</span>(<span class="st">"MID"</span> <span class="ot">=</span> <span class="st">"ID"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb72-7"><a href="#cb72-7" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">m_race =</span> Race) <span class="sc">%&gt;%</span></span>
<span id="cb72-8"><a href="#cb72-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">left_join</span>(race, <span class="at">by =</span> <span class="fu">c</span>(<span class="st">"FID"</span> <span class="ot">=</span> <span class="st">"ID"</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb72-9"><a href="#cb72-9" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">f_race =</span> Race)<span class="sc">%&gt;%</span></span>
<span id="cb72-10"><a href="#cb72-10" aria-hidden="true" tabindex="-1"></a>  <span class="fu">left_join</span>(cpi)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Joining with `by = join_by(year)`</code></pre>
</div>
</div>
</section>
<section id="clean-and-prepare-labor-market-data" class="level2">
<h2 class="anchored" data-anchor-id="clean-and-prepare-labor-market-data">Clean and Prepare Labor Market Data</h2>
<p>Labor market earnings and hours come from the main interview of the PSID, which collects information for the “husband”, the “wife” and other family members. Individuals can be matched to these variables via their sequence number in the household (which we will do below).</p>
<p>We first merge with the main panel and assign wages, earnings, and hours, based on the mother’s and father’s sequence number, which tells us if they are either the “husband” or “wife” in the household.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb74"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb74-1"><a href="#cb74-1" aria-hidden="true" tabindex="-1"></a>earnings_panel <span class="ot">&lt;-</span> mother_panel <span class="sc">%&gt;%</span></span>
<span id="cb74-2"><a href="#cb74-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(MID, FID, year, intnum, sn, snF) <span class="sc">%&gt;%</span></span>
<span id="cb74-3"><a href="#cb74-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">inner_join</span>(earnings_panel) <span class="sc">%&gt;%</span> <span class="co">#&lt;- merge based on year and interview number</span></span>
<span id="cb74-4"><a href="#cb74-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">m_hrs =</span> <span class="fu">case_when</span>(sn <span class="sc">==</span> <span class="dv">1</span> <span class="sc">~</span> hours_head, sn <span class="sc">==</span> <span class="dv">2</span> <span class="sc">~</span> hours_spouse), <span class="at">m_earn =</span> <span class="fu">case_when</span>(sn <span class="sc">==</span> <span class="dv">1</span> <span class="sc">~</span> earn_head, sn <span class="sc">==</span> <span class="dv">2</span> <span class="sc">~</span> earn_spouse)) <span class="sc">%&gt;%</span></span>
<span id="cb74-5"><a href="#cb74-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">f_hrs =</span> <span class="fu">case_when</span>(snF <span class="sc">==</span> <span class="dv">1</span> <span class="sc">~</span> hours_head, snF <span class="sc">==</span> <span class="dv">2</span> <span class="sc">~</span> hours_spouse), <span class="at">f_earn =</span> <span class="fu">case_when</span>(snF <span class="sc">==</span> <span class="dv">1</span> <span class="sc">~</span> earn_head, snF <span class="sc">==</span> <span class="dv">2</span> <span class="sc">~</span> earn_spouse)) <span class="sc">%&gt;%</span></span>
<span id="cb74-6"><a href="#cb74-6" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">m_wage =</span> m_earn <span class="sc">/</span> m_hrs, <span class="at">f_wage =</span> f_earn <span class="sc">/</span> f_hrs) <span class="sc">%&gt;%</span></span>
<span id="cb74-7"><a href="#cb74-7" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(MID, year, m_earn, m_hrs, m_wage, f_earn, f_hrs, f_wage) <span class="sc">%&gt;%</span> <span class="co">#&lt;- we don't keep FID because the coupling MID,FID is dynamic and may not match the pair (MID,FID) from the previous year when we merge these data back in</span></span>
<span id="cb74-8"><a href="#cb74-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">year =</span> year <span class="sc">-</span> <span class="dv">1</span>) <span class="co">#&lt;- these variable refer to the previous year so we subtract one</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Joining with `by = join_by(year, intnum)`</code></pre>
</div>
</div>
<p>Then we do the same with the T2 supplement data.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb76"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb76-1"><a href="#cb76-1" aria-hidden="true" tabindex="-1"></a><span class="co"># we link first to mothers:</span></span>
<span id="cb76-2"><a href="#cb76-2" aria-hidden="true" tabindex="-1"></a>T2m <span class="ot">&lt;-</span> mother_panel <span class="sc">%&gt;%</span></span>
<span id="cb76-3"><a href="#cb76-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(MID) <span class="sc">%&gt;%</span></span>
<span id="cb76-4"><a href="#cb76-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">unique</span>() <span class="sc">%&gt;%</span></span>
<span id="cb76-5"><a href="#cb76-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">inner_join</span>(earnings_panel_supplement) <span class="sc">%&gt;%</span> <span class="co">#&lt;- first four lines pick out mothers in CDS sample</span></span>
<span id="cb76-6"><a href="#cb76-6" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">m_earn =</span> earn, <span class="at">m_hrs =</span> hrs) <span class="sc">%&gt;%</span></span>
<span id="cb76-7"><a href="#cb76-7" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">m_wage =</span> m_earn <span class="sc">/</span> m_hrs) <span class="sc">%&gt;%</span></span>
<span id="cb76-8"><a href="#cb76-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(MID, year, m_earn, m_wage, m_hrs) <span class="co">#&lt;- these are mothers so drop the FID variable</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Joining with `by = join_by(MID)`</code></pre>
</div>
<div class="sourceCode cell-code" id="cb78"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb78-1"><a href="#cb78-1" aria-hidden="true" tabindex="-1"></a><span class="co"># and then to fathers</span></span>
<span id="cb78-2"><a href="#cb78-2" aria-hidden="true" tabindex="-1"></a>T2f <span class="ot">&lt;-</span> mother_panel <span class="sc">%&gt;%</span></span>
<span id="cb78-3"><a href="#cb78-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(FID) <span class="sc">%&gt;%</span></span>
<span id="cb78-4"><a href="#cb78-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">unique</span>() <span class="sc">%&gt;%</span></span>
<span id="cb78-5"><a href="#cb78-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">inner_join</span>(earnings_panel_supplement) <span class="sc">%&gt;%</span> <span class="co">#&lt;-first four lines pick out "fathers" in sample (recall we are labelling all spouses as fathers)</span></span>
<span id="cb78-6"><a href="#cb78-6" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">f_earn =</span> earn, <span class="at">f_hrs =</span> hrs) <span class="sc">%&gt;%</span></span>
<span id="cb78-7"><a href="#cb78-7" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">f_wage =</span> f_earn <span class="sc">/</span> f_hrs) <span class="sc">%&gt;%</span></span>
<span id="cb78-8"><a href="#cb78-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(FID, year, f_earn, f_wage, f_hrs) <span class="co">#&lt;- these are fathers so drop the MID variable</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Joining with `by = join_by(FID)`</code></pre>
</div>
<div class="sourceCode cell-code" id="cb80"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb80-1"><a href="#cb80-1" aria-hidden="true" tabindex="-1"></a><span class="co"># now we link the pair (MID,FID,year) first to mothers (MID,year) and then to fathers (MID,year), *then* we append all of this to the data from the main interview</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Join the data on total family income and taxable income of head ans spouse by family interview number and year.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb81"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb81-1"><a href="#cb81-1" aria-hidden="true" tabindex="-1"></a>mother_panel <span class="ot">&lt;-</span> mother_panel <span class="sc">%&gt;%</span></span>
<span id="cb81-2"><a href="#cb81-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">left_join</span>(total_income)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Joining with `by = join_by(year, MID)`</code></pre>
</div>
</div>
</section>
<section id="merge-in-labor-market-earnings-hours-wages" class="level2">
<h2 class="anchored" data-anchor-id="merge-in-labor-market-earnings-hours-wages">Merge in Labor Market Earnings, Hours, Wages</h2>
<p>We finish by (1) linking each of these files to mothers and fathers in our panel sample; (2) Adding this to the data from the main interview; and (3) Merging with the panel dataset.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb83"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb83-1"><a href="#cb83-1" aria-hidden="true" tabindex="-1"></a>mother_panel <span class="ot">&lt;-</span> mother_panel <span class="sc">%&gt;%</span></span>
<span id="cb83-2"><a href="#cb83-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(MID, FID, year) <span class="sc">%&gt;%</span></span>
<span id="cb83-3"><a href="#cb83-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">inner_join</span>(T2m) <span class="sc">%&gt;%</span></span>
<span id="cb83-4"><a href="#cb83-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">left_join</span>(T2f) <span class="sc">%&gt;%</span></span>
<span id="cb83-5"><a href="#cb83-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(<span class="sc">-</span>FID) <span class="sc">%&gt;%</span></span>
<span id="cb83-6"><a href="#cb83-6" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rbind</span>(earnings_panel) <span class="sc">%&gt;%</span> <span class="co">#&lt;- add all of this to the original data frame with the interview year questions</span></span>
<span id="cb83-7"><a href="#cb83-7" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">house_earn =</span> <span class="fu">case_when</span>(<span class="sc">!</span><span class="fu">is.na</span>(f_earn) <span class="sc">~</span> f_earn <span class="sc">+</span> m_earn, <span class="cn">TRUE</span> <span class="sc">~</span> m_earn), <span class="at">m_wage =</span> <span class="fu">na_if</span>(<span class="fu">na_if</span>(m_wage, <span class="cn">Inf</span>), <span class="dv">0</span>), <span class="at">f_wage =</span> <span class="fu">na_if</span>(<span class="fu">na_if</span>(f_wage, <span class="cn">Inf</span>), <span class="dv">0</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb83-8"><a href="#cb83-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">right_join</span>(mother_panel) <span class="co"># %&gt;%</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Joining with `by = join_by(MID, year)`
Joining with `by = join_by(FID, year)`
Joining with `by = join_by(MID, year)`</code></pre>
</div>
<div class="sourceCode cell-code" id="cb85"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb85-1"><a href="#cb85-1" aria-hidden="true" tabindex="-1"></a><span class="co">#load occupation data ad assign occupation to wife and husband by interview number and sequence number</span></span>
<span id="cb85-2"><a href="#cb85-2" aria-hidden="true" tabindex="-1"></a>occupations <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="st">"../../../data/data_PSID/main/occupation/output/occ.csv"</span>)</span>
<span id="cb85-3"><a href="#cb85-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb85-4"><a href="#cb85-4" aria-hidden="true" tabindex="-1"></a>mother_panel <span class="ot">&lt;-</span> mother_panel <span class="sc">%&gt;%</span></span>
<span id="cb85-5"><a href="#cb85-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">left_join</span>(occupations)<span class="sc">%&gt;%</span></span>
<span id="cb85-6"><a href="#cb85-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">m_occ_major =</span> <span class="fu">case_when</span>(sn <span class="sc">==</span> <span class="dv">1</span> <span class="sc">~</span> occ_major_h, sn <span class="sc">==</span> <span class="dv">2</span> <span class="sc">~</span> occ_major_s),</span>
<span id="cb85-7"><a href="#cb85-7" aria-hidden="true" tabindex="-1"></a>        <span class="at">m_occ_minor =</span> <span class="fu">case_when</span>(sn <span class="sc">==</span> <span class="dv">1</span> <span class="sc">~</span> occ_minor_h, sn <span class="sc">==</span> <span class="dv">2</span> <span class="sc">~</span> occ_minor_s),</span>
<span id="cb85-8"><a href="#cb85-8" aria-hidden="true" tabindex="-1"></a>        <span class="at">f_occ_major =</span> <span class="fu">case_when</span>(snF <span class="sc">==</span> <span class="dv">1</span> <span class="sc">~</span> occ_major_h, snF <span class="sc">==</span> <span class="dv">2</span> <span class="sc">~</span> occ_major_s),</span>
<span id="cb85-9"><a href="#cb85-9" aria-hidden="true" tabindex="-1"></a>        <span class="at">f_occ_minor =</span> <span class="fu">case_when</span>(snF <span class="sc">==</span> <span class="dv">1</span> <span class="sc">~</span> occ_minor_h, snF <span class="sc">==</span> <span class="dv">2</span> <span class="sc">~</span> occ_minor_s))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Joining with `by = join_by(year, intnum)`</code></pre>
</div>
</div>
</section>
<section id="sample-restrictions-and-creating-final-variables" class="level2">
<h2 class="anchored" data-anchor-id="sample-restrictions-and-creating-final-variables">Sample restrictions and creating final variables</h2>
<p>Create some missing variables.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb87"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb87-1"><a href="#cb87-1" aria-hidden="true" tabindex="-1"></a>mother_panel <span class="ot">&lt;-</span> mother_panel <span class="sc">%&gt;%</span> <span class="co">#set to missing age of children if no children</span></span>
<span id="cb87-2"><a href="#cb87-2" aria-hidden="true" tabindex="-1"></a>      <span class="fu">mutate</span>(</span>
<span id="cb87-3"><a href="#cb87-3" aria-hidden="true" tabindex="-1"></a>      <span class="at">age_oldest =</span> <span class="fu">replace</span>(age_oldest, <span class="fu">which</span>(num_child<span class="sc">==</span><span class="dv">0</span>), <span class="cn">NA_real_</span>),</span>
<span id="cb87-4"><a href="#cb87-4" aria-hidden="true" tabindex="-1"></a>      <span class="at">age_youngest =</span> <span class="fu">replace</span>(age_youngest, <span class="fu">which</span>(num_child<span class="sc">==</span><span class="dv">0</span>), <span class="cn">NA_real_</span>),</span>
<span id="cb87-5"><a href="#cb87-5" aria-hidden="true" tabindex="-1"></a><span class="co">#set to missing earnings if negative</span></span>
<span id="cb87-6"><a href="#cb87-6" aria-hidden="true" tabindex="-1"></a>      <span class="at">m_earn =</span> <span class="fu">replace</span>(m_earn, <span class="fu">which</span>(m_earn<span class="sc">&lt;</span><span class="dv">0</span>), <span class="cn">NA_real_</span>),</span>
<span id="cb87-7"><a href="#cb87-7" aria-hidden="true" tabindex="-1"></a>      <span class="at">f_earn =</span> <span class="fu">replace</span>(f_earn, <span class="fu">which</span>(f_earn<span class="sc">&lt;</span><span class="dv">0</span>), <span class="cn">NA_real_</span>),</span>
<span id="cb87-8"><a href="#cb87-8" aria-hidden="true" tabindex="-1"></a>      <span class="at">m_wage =</span> <span class="fu">replace</span>(m_wage, <span class="fu">which</span>(m_wage<span class="sc">&lt;</span><span class="dv">0</span>), <span class="cn">NA_real_</span>),</span>
<span id="cb87-9"><a href="#cb87-9" aria-hidden="true" tabindex="-1"></a>      <span class="at">f_wage =</span> <span class="fu">replace</span>(f_wage, <span class="fu">which</span>(f_wage<span class="sc">&lt;</span><span class="dv">0</span>),<span class="cn">NA_real_</span>),</span>
<span id="cb87-10"><a href="#cb87-10" aria-hidden="true" tabindex="-1"></a>      <span class="at">house_earn =</span> <span class="fu">replace</span>(house_earn, <span class="fu">which</span>(house_earn<span class="sc">&lt;</span><span class="dv">0</span>), <span class="cn">NA_real_</span>)</span>
<span id="cb87-11"><a href="#cb87-11" aria-hidden="true" tabindex="-1"></a>    )</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Define some new variables for later convenience in estimation.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb88"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb88-1"><a href="#cb88-1" aria-hidden="true" tabindex="-1"></a>mother_panel <span class="ot">&lt;-</span> mother_panel <span class="sc">%&gt;%</span> </span>
<span id="cb88-2"><a href="#cb88-2" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(</span>
<span id="cb88-3"><a href="#cb88-3" aria-hidden="true" tabindex="-1"></a>    <span class="co"># generate 0/1 indicator for current marrital status</span></span>
<span id="cb88-4"><a href="#cb88-4" aria-hidden="true" tabindex="-1"></a>    <span class="at">curr_married=</span><span class="fu">case_when</span>(</span>
<span id="cb88-5"><a href="#cb88-5" aria-hidden="true" tabindex="-1"></a>      mar_stat <span class="sc">==</span> <span class="st">"TRUE"</span> <span class="sc">~</span> <span class="dv">1</span>, </span>
<span id="cb88-6"><a href="#cb88-6" aria-hidden="true" tabindex="-1"></a>      mar_stat <span class="sc">==</span> <span class="st">"FALSE"</span> <span class="sc">~</span> <span class="dv">0</span>),</span>
<span id="cb88-7"><a href="#cb88-7" aria-hidden="true" tabindex="-1"></a>    <span class="co">#generate race indicators for mothers</span></span>
<span id="cb88-8"><a href="#cb88-8" aria-hidden="true" tabindex="-1"></a>    <span class="at">m_white =</span> <span class="fu">ifelse</span>(m_race<span class="sc">==</span><span class="dv">1</span>,<span class="dv">1</span>,<span class="dv">0</span>), </span>
<span id="cb88-9"><a href="#cb88-9" aria-hidden="true" tabindex="-1"></a>    <span class="at">m_black=</span><span class="fu">ifelse</span>(m_race<span class="sc">==</span><span class="dv">2</span>,<span class="dv">1</span>,<span class="dv">0</span>), </span>
<span id="cb88-10"><a href="#cb88-10" aria-hidden="true" tabindex="-1"></a>    <span class="at">m_r_oth=</span><span class="fu">ifelse</span>(m_race<span class="sc">&gt;</span><span class="dv">2</span>,<span class="dv">1</span>,<span class="dv">0</span>),</span>
<span id="cb88-11"><a href="#cb88-11" aria-hidden="true" tabindex="-1"></a>    <span class="co">#generate race indicators for fathers</span></span>
<span id="cb88-12"><a href="#cb88-12" aria-hidden="true" tabindex="-1"></a>    <span class="at">f_white =</span> <span class="fu">ifelse</span>(f_race<span class="sc">==</span><span class="dv">1</span>,<span class="dv">1</span>,<span class="dv">0</span>), </span>
<span id="cb88-13"><a href="#cb88-13" aria-hidden="true" tabindex="-1"></a>    <span class="at">f_black=</span><span class="fu">ifelse</span>(f_race<span class="sc">==</span><span class="dv">2</span>,<span class="dv">1</span>,<span class="dv">0</span>), </span>
<span id="cb88-14"><a href="#cb88-14" aria-hidden="true" tabindex="-1"></a>    <span class="at">f_r_oth=</span><span class="fu">ifelse</span>(f_race<span class="sc">&gt;</span><span class="dv">2</span>,<span class="dv">1</span>,<span class="dv">0</span>),</span>
<span id="cb88-15"><a href="#cb88-15" aria-hidden="true" tabindex="-1"></a>    <span class="co">#generate education indicators for fathers</span></span>
<span id="cb88-16"><a href="#cb88-16" aria-hidden="true" tabindex="-1"></a>    <span class="at">fed_hsd =</span> <span class="fu">ifelse</span>(f_ed<span class="sc">==</span> <span class="st">"&lt;12"</span>,<span class="dv">1</span>,<span class="dv">0</span>),</span>
<span id="cb88-17"><a href="#cb88-17" aria-hidden="true" tabindex="-1"></a>    <span class="at">fed_hs =</span> <span class="fu">ifelse</span>(f_ed<span class="sc">==</span> <span class="st">"12"</span>,<span class="dv">1</span>,<span class="dv">0</span>),</span>
<span id="cb88-18"><a href="#cb88-18" aria-hidden="true" tabindex="-1"></a>    <span class="at">fed_scoll =</span> <span class="fu">ifelse</span>(f_ed<span class="sc">==</span> <span class="st">"13-15"</span>,<span class="dv">1</span>,<span class="dv">0</span>),</span>
<span id="cb88-19"><a href="#cb88-19" aria-hidden="true" tabindex="-1"></a>    <span class="at">fed_coll =</span> <span class="fu">ifelse</span>(f_ed<span class="sc">==</span> <span class="st">"16"</span>,<span class="dv">1</span>,<span class="dv">0</span>),</span>
<span id="cb88-20"><a href="#cb88-20" aria-hidden="true" tabindex="-1"></a>    <span class="at">fed_postcol =</span> <span class="fu">ifelse</span>(f_ed<span class="sc">==</span> <span class="st">"&gt;16"</span>,<span class="dv">1</span>,<span class="dv">0</span>),</span>
<span id="cb88-21"><a href="#cb88-21" aria-hidden="true" tabindex="-1"></a>    <span class="at">fed_collplus =</span> fed_coll<span class="sc">+</span>fed_postcol,</span>
<span id="cb88-22"><a href="#cb88-22" aria-hidden="true" tabindex="-1"></a>    <span class="at">fed_scollplus =</span>fed_scoll<span class="sc">+</span> fed_coll<span class="sc">+</span>fed_postcol,</span>
<span id="cb88-23"><a href="#cb88-23" aria-hidden="true" tabindex="-1"></a>    <span class="co">#generate education indicators for mothers</span></span>
<span id="cb88-24"><a href="#cb88-24" aria-hidden="true" tabindex="-1"></a>    <span class="at">med_hsd =</span> <span class="fu">ifelse</span>(m_ed<span class="sc">==</span> <span class="st">"&lt;12"</span>,<span class="dv">1</span>,<span class="dv">0</span>),</span>
<span id="cb88-25"><a href="#cb88-25" aria-hidden="true" tabindex="-1"></a>    <span class="at">med_hs =</span> <span class="fu">ifelse</span>(m_ed<span class="sc">==</span> <span class="st">"12"</span>,<span class="dv">1</span>,<span class="dv">0</span>),</span>
<span id="cb88-26"><a href="#cb88-26" aria-hidden="true" tabindex="-1"></a>    <span class="at">med_scoll =</span> <span class="fu">ifelse</span>(m_ed<span class="sc">==</span> <span class="st">"13-15"</span>,<span class="dv">1</span>,<span class="dv">0</span>),</span>
<span id="cb88-27"><a href="#cb88-27" aria-hidden="true" tabindex="-1"></a>    <span class="at">med_coll =</span> <span class="fu">ifelse</span>(m_ed<span class="sc">==</span> <span class="st">"16"</span>,<span class="dv">1</span>,<span class="dv">0</span>),</span>
<span id="cb88-28"><a href="#cb88-28" aria-hidden="true" tabindex="-1"></a>    <span class="at">med_postcol  =</span> <span class="fu">ifelse</span>(m_ed<span class="sc">==</span> <span class="st">"&gt;16"</span>,<span class="dv">1</span>,<span class="dv">0</span>),</span>
<span id="cb88-29"><a href="#cb88-29" aria-hidden="true" tabindex="-1"></a>    <span class="at">med_collplus =</span> med_coll<span class="sc">+</span>med_postcol,</span>
<span id="cb88-30"><a href="#cb88-30" aria-hidden="true" tabindex="-1"></a>    <span class="at">med_scollplus =</span> med_scoll<span class="sc">+</span>med_coll<span class="sc">+</span>med_postcol,</span>
<span id="cb88-31"><a href="#cb88-31" aria-hidden="true" tabindex="-1"></a>    <span class="co">#generate a variable measuring number of children younger than 12</span></span>
<span id="cb88-32"><a href="#cb88-32" aria-hidden="true" tabindex="-1"></a>    <span class="at">num_0_12=</span>num_0_5<span class="sc">+</span>num_6_12,</span>
<span id="cb88-33"><a href="#cb88-33" aria-hidden="true" tabindex="-1"></a>    <span class="co">#mom age at oldest child's birth</span></span>
<span id="cb88-34"><a href="#cb88-34" aria-hidden="true" tabindex="-1"></a>    <span class="at">momageatbirth1 =</span> m_age <span class="sc">-</span> age_oldest,</span>
<span id="cb88-35"><a href="#cb88-35" aria-hidden="true" tabindex="-1"></a>    <span class="co"># create measures of potential work experience</span></span>
<span id="cb88-36"><a href="#cb88-36" aria-hidden="true" tabindex="-1"></a>    <span class="at">m_exper =</span> <span class="fu">case_when</span>( med_scoll <span class="sc">==</span> <span class="dv">1</span><span class="sc">~</span>m_age<span class="dv">-20</span>, med_coll <span class="sc">==</span> <span class="dv">1</span> <span class="sc">~</span> m_age<span class="dv">-22</span>, med_postcol <span class="sc">==</span> <span class="dv">1</span> <span class="sc">~</span> m_age<span class="dv">-24</span>, <span class="cn">TRUE</span> <span class="sc">~</span>m_age<span class="dv">-18</span>),</span>
<span id="cb88-37"><a href="#cb88-37" aria-hidden="true" tabindex="-1"></a>    <span class="at">f_exper =</span> <span class="fu">case_when</span> ( fed_scoll <span class="sc">==</span> <span class="dv">1</span><span class="sc">~</span> f_age<span class="dv">-20</span>, fed_coll <span class="sc">==</span> <span class="dv">1</span> <span class="sc">~</span> f_age<span class="dv">-22</span>, fed_postcol <span class="sc">==</span> <span class="dv">1</span> <span class="sc">~</span> f_age<span class="dv">-24</span>, <span class="cn">TRUE</span> <span class="sc">~</span>f_age<span class="dv">-18</span>),</span>
<span id="cb88-38"><a href="#cb88-38" aria-hidden="true" tabindex="-1"></a>    <span class="at">m_exper2 =</span> m_exper<span class="sc">*</span>m_exper,</span>
<span id="cb88-39"><a href="#cb88-39" aria-hidden="true" tabindex="-1"></a>    <span class="at">f_exper2 =</span> f_exper<span class="sc">*</span>f_exper)</span>
<span id="cb88-40"><a href="#cb88-40" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb88-41"><a href="#cb88-41" aria-hidden="true" tabindex="-1"></a><span class="co">#Generate non-labour income measure for married and single parents</span></span>
<span id="cb88-42"><a href="#cb88-42" aria-hidden="true" tabindex="-1"></a>mother_panel <span class="ot">&lt;-</span> mother_panel <span class="sc">%&gt;%</span></span>
<span id="cb88-43"><a href="#cb88-43" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">non_lab_income=</span> <span class="fu">case_when</span>(</span>
<span id="cb88-44"><a href="#cb88-44" aria-hidden="true" tabindex="-1"></a>    curr_married <span class="sc">==</span> <span class="dv">1</span> <span class="sc">~</span> total_income<span class="sc">-</span>m_earn<span class="sc">-</span>f_earn,</span>
<span id="cb88-45"><a href="#cb88-45" aria-hidden="true" tabindex="-1"></a>    curr_married <span class="sc">==</span> <span class="dv">0</span> <span class="sc">~</span> total_income<span class="sc">-</span>m_earn)</span>
<span id="cb88-46"><a href="#cb88-46" aria-hidden="true" tabindex="-1"></a>    ) <span class="sc">%&gt;%</span></span>
<span id="cb88-47"><a href="#cb88-47" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">non_lab_income=</span>non_lab_income<span class="sc">/</span><span class="dv">52</span>) <span class="co">#annual to weekly</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Define a variable indicating whether in sample.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb89"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb89-1"><a href="#cb89-1" aria-hidden="true" tabindex="-1"></a>mother_panel <span class="ot">&lt;-</span> mother_panel <span class="sc">%&gt;%</span></span>
<span id="cb89-2"><a href="#cb89-2" aria-hidden="true" tabindex="-1"></a>  <span class="co">#mom is between 16 and 45 at birth of the oldest child (or missing)%&gt;%</span></span>
<span id="cb89-3"><a href="#cb89-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb89-4"><a href="#cb89-4" aria-hidden="true" tabindex="-1"></a>    <span class="at">ind_not_sample=</span><span class="fu">case_when</span>(</span>
<span id="cb89-5"><a href="#cb89-5" aria-hidden="true" tabindex="-1"></a>      momageatbirth1<span class="sc">&gt;=</span><span class="dv">16</span> <span class="sc">&amp;</span> momageatbirth1<span class="sc">&lt;=</span><span class="dv">45</span> <span class="sc">~</span> <span class="dv">0</span>,</span>
<span id="cb89-6"><a href="#cb89-6" aria-hidden="true" tabindex="-1"></a>      <span class="fu">is.na</span>(momageatbirth1)<span class="sc">==</span><span class="dv">1</span><span class="sc">~</span><span class="dv">0</span>, </span>
<span id="cb89-7"><a href="#cb89-7" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span><span class="sc">~</span><span class="dv">1</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb89-8"><a href="#cb89-8" aria-hidden="true" tabindex="-1"></a>    <span class="co">#mom and dad are between 18 and 65 or age missing</span></span>
<span id="cb89-9"><a href="#cb89-9" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb89-10"><a href="#cb89-10" aria-hidden="true" tabindex="-1"></a>    <span class="at">ind_not_sample=</span><span class="fu">case_when</span>(</span>
<span id="cb89-11"><a href="#cb89-11" aria-hidden="true" tabindex="-1"></a>      m_age<span class="sc">&gt;=</span><span class="dv">18</span><span class="sc">&amp;</span>m_age<span class="sc">&lt;=</span><span class="dv">65</span> <span class="sc">~</span> ind_not_sample,</span>
<span id="cb89-12"><a href="#cb89-12" aria-hidden="true" tabindex="-1"></a>      <span class="fu">is.na</span>(m_age)<span class="sc">==</span><span class="dv">1</span><span class="sc">~</span>ind_not_sample, </span>
<span id="cb89-13"><a href="#cb89-13" aria-hidden="true" tabindex="-1"></a>      <span class="cn">TRUE</span><span class="sc">~</span><span class="dv">1</span>)</span>
<span id="cb89-14"><a href="#cb89-14" aria-hidden="true" tabindex="-1"></a>      ) <span class="sc">%&gt;%</span></span>
<span id="cb89-15"><a href="#cb89-15" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb89-16"><a href="#cb89-16" aria-hidden="true" tabindex="-1"></a>    <span class="at">ind_not_sample=</span><span class="fu">case_when</span>(</span>
<span id="cb89-17"><a href="#cb89-17" aria-hidden="true" tabindex="-1"></a>      f_age<span class="sc">&gt;=</span><span class="dv">18</span><span class="sc">&amp;</span>f_age<span class="sc">&lt;=</span><span class="dv">65</span> <span class="sc">~</span> ind_not_sample,</span>
<span id="cb89-18"><a href="#cb89-18" aria-hidden="true" tabindex="-1"></a>      <span class="fu">is.na</span>(f_age)<span class="sc">==</span><span class="dv">1</span> <span class="sc">~</span> ind_not_sample, <span class="cn">TRUE</span><span class="sc">~</span><span class="dv">1</span>)</span>
<span id="cb89-19"><a href="#cb89-19" aria-hidden="true" tabindex="-1"></a>      )</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Censor wages based on quantiles of the sample.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb90"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb90-1"><a href="#cb90-1" aria-hidden="true" tabindex="-1"></a><span class="co">#Calculate quantiles for observations that will remain in the sample (ind_not_sample==0) by year\broad education group</span></span>
<span id="cb90-2"><a href="#cb90-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb90-3"><a href="#cb90-3" aria-hidden="true" tabindex="-1"></a>q_m <span class="ot">&lt;-</span> mother_panel <span class="sc">%&gt;%</span></span>
<span id="cb90-4"><a href="#cb90-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(ind_not_sample<span class="sc">==</span><span class="dv">0</span>)<span class="sc">%&gt;%</span></span>
<span id="cb90-5"><a href="#cb90-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(year, med_scollplus) <span class="sc">%&gt;%</span></span>
<span id="cb90-6"><a href="#cb90-6" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarize</span>(</span>
<span id="cb90-7"><a href="#cb90-7" aria-hidden="true" tabindex="-1"></a>    <span class="at">qm1 =</span> <span class="fu">quantile</span>(m_wage, <span class="fl">0.01</span>, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb90-8"><a href="#cb90-8" aria-hidden="true" tabindex="-1"></a>    <span class="at">qm99 =</span> <span class="fu">quantile</span>(m_wage, <span class="at">probs =</span> <span class="fl">0.99</span>, <span class="at">na.rm =</span> <span class="cn">TRUE</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>`summarise()` has grouped output by 'year'. You can override using the
`.groups` argument.</code></pre>
</div>
<div class="sourceCode cell-code" id="cb92"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb92-1"><a href="#cb92-1" aria-hidden="true" tabindex="-1"></a>q_f <span class="ot">&lt;-</span> mother_panel <span class="sc">%&gt;%</span></span>
<span id="cb92-2"><a href="#cb92-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(ind_not_sample<span class="sc">==</span><span class="dv">0</span>)<span class="sc">%&gt;%</span></span>
<span id="cb92-3"><a href="#cb92-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(year, fed_scollplus) <span class="sc">%&gt;%</span></span>
<span id="cb92-4"><a href="#cb92-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summarize</span>(</span>
<span id="cb92-5"><a href="#cb92-5" aria-hidden="true" tabindex="-1"></a>    <span class="at">qf1 =</span> <span class="fu">quantile</span>(f_wage, <span class="fl">0.01</span>, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb92-6"><a href="#cb92-6" aria-hidden="true" tabindex="-1"></a>    <span class="at">qf99 =</span> <span class="fu">quantile</span>(f_wage, <span class="at">probs =</span> <span class="fl">0.99</span>, <span class="at">na.rm =</span> <span class="cn">TRUE</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>`summarise()` has grouped output by 'year'. You can override using the
`.groups` argument.</code></pre>
</div>
<div class="sourceCode cell-code" id="cb94"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb94-1"><a href="#cb94-1" aria-hidden="true" tabindex="-1"></a>mother_panel <span class="ot">&lt;-</span> mother_panel <span class="sc">%&gt;%</span></span>
<span id="cb94-2"><a href="#cb94-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">left_join</span>(q_m) <span class="sc">%&gt;%</span></span>
<span id="cb94-3"><a href="#cb94-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">left_join</span>(q_f) <span class="sc">%&gt;%</span></span>
<span id="cb94-4"><a href="#cb94-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">m_wage=</span><span class="fu">case_when</span>(m_wage <span class="sc">&gt;=</span> qm1 <span class="sc">&amp;</span> m_wage <span class="sc">&lt;=</span> qm99 <span class="sc">~</span> m_wage, <span class="cn">TRUE</span><span class="sc">~</span> <span class="cn">NA_real_</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb94-5"><a href="#cb94-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">f_wage=</span>  <span class="fu">case_when</span>(f_wage <span class="sc">&gt;=</span> qf1 <span class="sc">&amp;</span> f_wage <span class="sc">&lt;=</span> qf99 <span class="sc">~</span> f_wage, <span class="cn">TRUE</span><span class="sc">~</span> <span class="cn">NA_real_</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb94-6"><a href="#cb94-6" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(<span class="sc">-</span>qf1,<span class="sc">-</span>qf99,<span class="sc">-</span>qm1,<span class="sc">-</span>qm99)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Joining with `by = join_by(year, med_scollplus)`
Joining with `by = join_by(year, fed_scollplus)`</code></pre>
</div>
<div class="sourceCode cell-code" id="cb96"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb96-1"><a href="#cb96-1" aria-hidden="true" tabindex="-1"></a><span class="co">#Deflate wages, annual earning,  non-labour income to 2002 dollars </span></span>
<span id="cb96-2"><a href="#cb96-2" aria-hidden="true" tabindex="-1"></a>mother_panel <span class="ot">&lt;-</span> mother_panel <span class="sc">%&gt;%</span></span>
<span id="cb96-3"><a href="#cb96-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">m_wage=</span>m_wage<span class="sc">/</span>CPIU,</span>
<span id="cb96-4"><a href="#cb96-4" aria-hidden="true" tabindex="-1"></a>          <span class="at">f_wage=</span>f_wage<span class="sc">/</span>CPIU,</span>
<span id="cb96-5"><a href="#cb96-5" aria-hidden="true" tabindex="-1"></a>          <span class="at">m_earn=</span>m_earn<span class="sc">/</span>CPIU,</span>
<span id="cb96-6"><a href="#cb96-6" aria-hidden="true" tabindex="-1"></a>          <span class="at">f_earn=</span>f_earn<span class="sc">/</span>CPIU,</span>
<span id="cb96-7"><a href="#cb96-7" aria-hidden="true" tabindex="-1"></a>          <span class="at">total_income=</span>total_income<span class="sc">/</span>CPIU,</span>
<span id="cb96-8"><a href="#cb96-8" aria-hidden="true" tabindex="-1"></a>          <span class="at">tax_income=</span>tax_income<span class="sc">/</span>CPIU,</span>
<span id="cb96-9"><a href="#cb96-9" aria-hidden="true" tabindex="-1"></a>          <span class="at">non_lab_income=</span>non_lab_income<span class="sc">/</span>CPIU)</span>
<span id="cb96-10"><a href="#cb96-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb96-11"><a href="#cb96-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb96-12"><a href="#cb96-12" aria-hidden="true" tabindex="-1"></a><span class="co"># Calculate log wage measures for trimmed wages</span></span>
<span id="cb96-13"><a href="#cb96-13" aria-hidden="true" tabindex="-1"></a>mother_panel <span class="ot">&lt;-</span> mother_panel <span class="sc">%&gt;%</span> </span>
<span id="cb96-14"><a href="#cb96-14" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(</span>
<span id="cb96-15"><a href="#cb96-15" aria-hidden="true" tabindex="-1"></a>        <span class="at">ln_wage_m=</span><span class="fu">log</span>(m_wage),</span>
<span id="cb96-16"><a href="#cb96-16" aria-hidden="true" tabindex="-1"></a>        <span class="at">ln_wage_f=</span><span class="fu">log</span>(f_wage),</span>
<span id="cb96-17"><a href="#cb96-17" aria-hidden="true" tabindex="-1"></a>        <span class="at">ln_wage_fm_ratio =</span> ln_wage_f <span class="sc">-</span> ln_wage_m)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Finally, save the panel dataset.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb97"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb97-1"><a href="#cb97-1" aria-hidden="true" tabindex="-1"></a><span class="fu">write.csv</span>(mother_panel, <span class="st">"../../../data/data_derived/MotherPanelCDS.csv"</span>)</span>
<span id="cb97-2"><a href="#cb97-2" aria-hidden="true" tabindex="-1"></a><span class="fu">write.dta</span>(mother_panel, <span class="st">"../../../data/data_derived/MotherPanelCDS.dta"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
</section>
<section id="assembling-a-panel-of-cds-children" class="level1">
<h1>Assembling a Panel of CDS Children</h1>
<div class="cell">
<div class="sourceCode cell-code" id="cb98"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb98-1"><a href="#cb98-1" aria-hidden="true" tabindex="-1"></a>child_panel <span class="ot">&lt;-</span> KID <span class="sc">%&gt;%</span></span>
<span id="cb98-2"><a href="#cb98-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">inner_join</span>(C) <span class="sc">%&gt;%</span></span>
<span id="cb98-3"><a href="#cb98-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">group_by</span>(KID) <span class="sc">%&gt;%</span></span>
<span id="cb98-4"><a href="#cb98-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(<span class="fu">sum</span>(CAH2 <span class="sc">==</span> <span class="dv">2</span>) <span class="sc">==</span> <span class="dv">0</span>) <span class="sc">%&gt;%</span> <span class="co"># drop children with adoption records</span></span>
<span id="cb98-5"><a href="#cb98-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">rename</span>(<span class="at">ybirth_child =</span> CAH15) <span class="sc">%&gt;%</span></span>
<span id="cb98-6"><a href="#cb98-6" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">ybirth_child =</span> <span class="fu">na_if</span>(ybirth_child, <span class="dv">9998</span>)) <span class="sc">%&gt;%</span></span>
<span id="cb98-7"><a href="#cb98-7" aria-hidden="true" tabindex="-1"></a>  <span class="fu">select</span>(MID, KID, ybirth_child) <span class="sc">%&gt;%</span></span>
<span id="cb98-8"><a href="#cb98-8" aria-hidden="true" tabindex="-1"></a>  <span class="fu">merge</span>(mother_panel) <span class="sc">%&gt;%</span></span>
<span id="cb98-9"><a href="#cb98-9" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">age =</span> year <span class="sc">-</span> ybirth_child) <span class="sc">%&gt;%</span></span>
<span id="cb98-10"><a href="#cb98-10" aria-hidden="true" tabindex="-1"></a>  <span class="fu">left_join</span>(assessment_panel) <span class="sc">%&gt;%</span></span>
<span id="cb98-11"><a href="#cb98-11" aria-hidden="true" tabindex="-1"></a>  <span class="fu">left_join</span>(cds_expenditures) <span class="sc">%&gt;%</span></span>
<span id="cb98-12"><a href="#cb98-12" aria-hidden="true" tabindex="-1"></a>  <span class="fu">left_join</span>(cds_childcare) <span class="sc">%&gt;%</span></span>
<span id="cb98-13"><a href="#cb98-13" aria-hidden="true" tabindex="-1"></a>  <span class="fu">left_join</span>(TD_agg) <span class="sc">%&gt;%</span></span>
<span id="cb98-14"><a href="#cb98-14" aria-hidden="true" tabindex="-1"></a>  <span class="fu">left_join</span>(PPE) <span class="sc">%&gt;%</span></span>
<span id="cb98-15"><a href="#cb98-15" aria-hidden="true" tabindex="-1"></a>  <span class="fu">left_join</span>(age_month)<span class="sc">%&gt;%</span></span>
<span id="cb98-16"><a href="#cb98-16" aria-hidden="true" tabindex="-1"></a>  <span class="fu">left_join</span>(staff_ratio_panel)<span class="sc">%&gt;%</span><span class="co">#staff to child ratios by age of child in months</span></span>
<span id="cb98-17"><a href="#cb98-17" aria-hidden="true" tabindex="-1"></a>  <span class="fu">left_join</span>(relative_present)<span class="sc">%&gt;%</span></span>
<span id="cb98-18"><a href="#cb98-18" aria-hidden="true" tabindex="-1"></a>  <span class="fu">filter</span>(year<span class="sc">&gt;=</span><span class="dv">1997</span>,year<span class="sc">&lt;=</span><span class="dv">2007</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Joining with `by = join_by(KID)`
Joining with `by = join_by(KID, year)`
Joining with `by = join_by(KID, year)`
Joining with `by = join_by(KID, year)`
Joining with `by = join_by(KID, year)`
Joining with `by = join_by(KID, year)`
Joining with `by = join_by(KID, year)`
Joining with `by = join_by(year, state_str, age_month)`
Joining with `by = join_by(KID, year)`</code></pre>
</div>
<div class="sourceCode cell-code" id="cb100"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb100-1"><a href="#cb100-1" aria-hidden="true" tabindex="-1"></a><span class="co">#Add mobility data and 1988 distance to parents</span></span>
<span id="cb100-2"><a href="#cb100-2" aria-hidden="true" tabindex="-1"></a>child_panel <span class="ot">&lt;-</span> child_panel <span class="sc">%&gt;%</span></span>
<span id="cb100-3"><a href="#cb100-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">left_join</span>(head_grow_up) <span class="sc">%&gt;%</span></span>
<span id="cb100-4"><a href="#cb100-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">left_join</span>(mother_distance) <span class="sc">%&gt;%</span></span>
<span id="cb100-5"><a href="#cb100-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">left_join</span>(father_distance) </span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Joining with `by = join_by(year, intnum)`
Joining with `by = join_by(MID)`
Joining with `by = join_by(FID)`</code></pre>
</div>
<div class="sourceCode cell-code" id="cb102"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb102-1"><a href="#cb102-1" aria-hidden="true" tabindex="-1"></a>child_panel <span class="ot">&lt;-</span> child_panel <span class="sc">%&gt;%</span> <span class="co">#generate HH weekly childcare expenditure per child</span></span>
<span id="cb102-2"><a href="#cb102-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">chcare_hh=</span>childcare_exp<span class="sc">/</span><span class="dv">52</span>,</span>
<span id="cb102-3"><a href="#cb102-3" aria-hidden="true" tabindex="-1"></a>         <span class="at">chcare_hh_pc=</span>chcare_hh<span class="sc">/</span>num_0_12,</span>
<span id="cb102-4"><a href="#cb102-4" aria-hidden="true" tabindex="-1"></a>         <span class="co">#generate total goods expenditures</span></span>
<span id="cb102-5"><a href="#cb102-5" aria-hidden="true" tabindex="-1"></a>         <span class="at">hhinvest =</span> SchSupplies <span class="sc">+</span> sports <span class="sc">+</span> lessons <span class="sc">+</span> comm_grps <span class="sc">+</span> tutoring <span class="sc">+</span> Toys)</span>
<span id="cb102-6"><a href="#cb102-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb102-7"><a href="#cb102-7" aria-hidden="true" tabindex="-1"></a>child_panel <span class="ot">&lt;-</span> child_panel <span class="sc">%&gt;%</span></span>
<span id="cb102-8"><a href="#cb102-8" aria-hidden="true" tabindex="-1"></a>  <span class="co">#generate age at birth of the child</span></span>
<span id="cb102-9"><a href="#cb102-9" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">momageatbirth=</span>m_age<span class="sc">-</span>age)</span>
<span id="cb102-10"><a href="#cb102-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb102-11"><a href="#cb102-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb102-12"><a href="#cb102-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb102-13"><a href="#cb102-13" aria-hidden="true" tabindex="-1"></a><span class="co"># Sample restriction: only households with children age 0-18</span></span>
<span id="cb102-14"><a href="#cb102-14" aria-hidden="true" tabindex="-1"></a>child_panel <span class="ot">&lt;-</span> child_panel <span class="sc">%&gt;%</span></span>
<span id="cb102-15"><a href="#cb102-15" aria-hidden="true" tabindex="-1"></a>  <span class="fu">mutate</span>(<span class="at">ind_not_sample=</span><span class="fu">case_when</span>((num_child<span class="sc">&gt;</span><span class="dv">0</span> <span class="sc">&amp;</span> age<span class="sc">&gt;=</span><span class="dv">0</span> <span class="sc">&amp;</span> age<span class="sc">&lt;=</span><span class="dv">18</span>) <span class="sc">~</span> ind_not_sample, <span class="cn">TRUE</span><span class="sc">~</span><span class="dv">1</span>))</span>
<span id="cb102-16"><a href="#cb102-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb102-17"><a href="#cb102-17" aria-hidden="true" tabindex="-1"></a><span class="co">#Deflate childcare and goods expenditures to 2002 dollars </span></span>
<span id="cb102-18"><a href="#cb102-18" aria-hidden="true" tabindex="-1"></a> child_panel <span class="ot">&lt;-</span> child_panel <span class="sc">%&gt;%</span></span>
<span id="cb102-19"><a href="#cb102-19" aria-hidden="true" tabindex="-1"></a>    <span class="fu">mutate</span>(<span class="at">chcare=</span>chcare<span class="sc">/</span>CPIU,</span>
<span id="cb102-20"><a href="#cb102-20" aria-hidden="true" tabindex="-1"></a>           <span class="at">chcare_second=</span>chcare_second<span class="sc">/</span>CPIU,</span>
<span id="cb102-21"><a href="#cb102-21" aria-hidden="true" tabindex="-1"></a>           <span class="at">chcare_hh_pc=</span>chcare_hh_pc<span class="sc">/</span>CPIU,</span>
<span id="cb102-22"><a href="#cb102-22" aria-hidden="true" tabindex="-1"></a>           <span class="at">chcare_hh =</span>chcare_hh <span class="sc">/</span>CPIU,</span>
<span id="cb102-23"><a href="#cb102-23" aria-hidden="true" tabindex="-1"></a>           <span class="at">hhinvest=</span>hhinvest<span class="sc">/</span>CPIU)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb103"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb103-1"><a href="#cb103-1" aria-hidden="true" tabindex="-1"></a><span class="fu">write.csv</span>(child_panel,<span class="st">"../../../data/data_derived/ChildPanelCDS.csv"</span>)</span>
<span id="cb103-2"><a href="#cb103-2" aria-hidden="true" tabindex="-1"></a><span class="fu">write.dta</span>(child_panel, <span class="st">"../../../data/data_derived/ChildPanelCDS.dta"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>

</main>
<!-- /main column -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
  const toggleBodyColorMode = (bsSheetEl) => {
    const mode = bsSheetEl.getAttribute("data-mode");
    const bodyEl = window.document.querySelector("body");
    if (mode === "dark") {
      bodyEl.classList.add("quarto-dark");
      bodyEl.classList.remove("quarto-light");
    } else {
      bodyEl.classList.add("quarto-light");
      bodyEl.classList.remove("quarto-dark");
    }
  }
  const toggleBodyColorPrimary = () => {
    const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
    if (bsSheetEl) {
      toggleBodyColorMode(bsSheetEl);
    }
  }
  toggleBodyColorPrimary();  
  const icon = "";
  const anchorJS = new window.AnchorJS();
  anchorJS.options = {
    placement: 'right',
    icon: icon
  };
  anchorJS.add('.anchored');
  const isCodeAnnotation = (el) => {
    for (const clz of el.classList) {
      if (clz.startsWith('code-annotation-')) {                     
        return true;
      }
    }
    return false;
  }
  const onCopySuccess = function(e) {
    // button target
    const button = e.trigger;
    // don't keep focus
    button.blur();
    // flash "checked"
    button.classList.add('code-copy-button-checked');
    var currentTitle = button.getAttribute("title");
    button.setAttribute("title", "Copied!");
    let tooltip;
    if (window.bootstrap) {
      button.setAttribute("data-bs-toggle", "tooltip");
      button.setAttribute("data-bs-placement", "left");
      button.setAttribute("data-bs-title", "Copied!");
      tooltip = new bootstrap.Tooltip(button, 
        { trigger: "manual", 
          customClass: "code-copy-button-tooltip",
          offset: [0, -8]});
      tooltip.show();    
    }
    setTimeout(function() {
      if (tooltip) {
        tooltip.hide();
        button.removeAttribute("data-bs-title");
        button.removeAttribute("data-bs-toggle");
        button.removeAttribute("data-bs-placement");
      }
      button.setAttribute("title", currentTitle);
      button.classList.remove('code-copy-button-checked');
    }, 1000);
    // clear code selection
    e.clearSelection();
  }
  const getTextToCopy = function(trigger) {
      const codeEl = trigger.previousElementSibling.cloneNode(true);
      for (const childEl of codeEl.children) {
        if (isCodeAnnotation(childEl)) {
          childEl.remove();
        }
      }
      return codeEl.innerText;
  }
  const clipboard = new window.ClipboardJS('.code-copy-button:not([data-in-quarto-modal])', {
    text: getTextToCopy
  });
  clipboard.on('success', onCopySuccess);
  if (window.document.getElementById('quarto-embedded-source-code-modal')) {
    const clipboardModal = new window.ClipboardJS('.code-copy-button[data-in-quarto-modal]', {
      text: getTextToCopy,
      container: window.document.getElementById('quarto-embedded-source-code-modal')
    });
    clipboardModal.on('success', onCopySuccess);
  }
    var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
    var mailtoRegex = new RegExp(/^mailto:/);
      var filterRegex = new RegExp('/' + window.location.host + '/');
    var isInternal = (href) => {
        return filterRegex.test(href) || localhostRegex.test(href) || mailtoRegex.test(href);
    }
    // Inspect non-navigation links and adorn them if external
 	var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item):not(.quarto-navigation-tool):not(.about-link)');
    for (var i=0; i<links.length; i++) {
      const link = links[i];
      if (!isInternal(link.href)) {
        // undo the damage that might have been done by quarto-nav.js in the case of
        // links that we want to consider external
        if (link.dataset.originalHref !== undefined) {
          link.href = link.dataset.originalHref;
        }
      }
    }
  function tippyHover(el, contentFn, onTriggerFn, onUntriggerFn) {
    const config = {
      allowHTML: true,
      maxWidth: 500,
      delay: 100,
      arrow: false,
      appendTo: function(el) {
          return el.parentElement;
      },
      interactive: true,
      interactiveBorder: 10,
      theme: 'quarto',
      placement: 'bottom-start',
    };
    if (contentFn) {
      config.content = contentFn;
    }
    if (onTriggerFn) {
      config.onTrigger = onTriggerFn;
    }
    if (onUntriggerFn) {
      config.onUntrigger = onUntriggerFn;
    }
    window.tippy(el, config); 
  }
  const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
  for (var i=0; i<noterefs.length; i++) {
    const ref = noterefs[i];
    tippyHover(ref, function() {
      // use id or data attribute instead here
      let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
      try { href = new URL(href).hash; } catch {}
      const id = href.replace(/^#\/?/, "");
      const note = window.document.getElementById(id);
      if (note) {
        return note.innerHTML;
      } else {
        return "";
      }
    });
  }
  const xrefs = window.document.querySelectorAll('a.quarto-xref');
  const processXRef = (id, note) => {
    // Strip column container classes
    const stripColumnClz = (el) => {
      el.classList.remove("page-full", "page-columns");
      if (el.children) {
        for (const child of el.children) {
          stripColumnClz(child);
        }
      }
    }
    stripColumnClz(note)
    if (id === null || id.startsWith('sec-')) {
      // Special case sections, only their first couple elements
      const container = document.createElement("div");
      if (note.children && note.children.length > 2) {
        container.appendChild(note.children[0].cloneNode(true));
        for (let i = 1; i < note.children.length; i++) {
          const child = note.children[i];
          if (child.tagName === "P" && child.innerText === "") {
            continue;
          } else {
            container.appendChild(child.cloneNode(true));
            break;
          }
        }
        if (window.Quarto?.typesetMath) {
          window.Quarto.typesetMath(container);
        }
        return container.innerHTML
      } else {
        if (window.Quarto?.typesetMath) {
          window.Quarto.typesetMath(note);
        }
        return note.innerHTML;
      }
    } else {
      // Remove any anchor links if they are present
      const anchorLink = note.querySelector('a.anchorjs-link');
      if (anchorLink) {
        anchorLink.remove();
      }
      if (window.Quarto?.typesetMath) {
        window.Quarto.typesetMath(note);
      }
      if (note.classList.contains("callout")) {
        return note.outerHTML;
      } else {
        return note.innerHTML;
      }
    }
  }
  for (var i=0; i<xrefs.length; i++) {
    const xref = xrefs[i];
    tippyHover(xref, undefined, function(instance) {
      instance.disable();
      let url = xref.getAttribute('href');
      let hash = undefined; 
      if (url.startsWith('#')) {
        hash = url;
      } else {
        try { hash = new URL(url).hash; } catch {}
      }
      if (hash) {
        const id = hash.replace(/^#\/?/, "");
        const note = window.document.getElementById(id);
        if (note !== null) {
          try {
            const html = processXRef(id, note.cloneNode(true));
            instance.setContent(html);
          } finally {
            instance.enable();
            instance.show();
          }
        } else {
          // See if we can fetch this
          fetch(url.split('#')[0])
          .then(res => res.text())
          .then(html => {
            const parser = new DOMParser();
            const htmlDoc = parser.parseFromString(html, "text/html");
            const note = htmlDoc.getElementById(id);
            if (note !== null) {
              const html = processXRef(id, note);
              instance.setContent(html);
            } 
          }).finally(() => {
            instance.enable();
            instance.show();
          });
        }
      } else {
        // See if we can fetch a full url (with no hash to target)
        // This is a special case and we should probably do some content thinning / targeting
        fetch(url)
        .then(res => res.text())
        .then(html => {
          const parser = new DOMParser();
          const htmlDoc = parser.parseFromString(html, "text/html");
          const note = htmlDoc.querySelector('main.content');
          if (note !== null) {
            // This should only happen for chapter cross references
            // (since there is no id in the URL)
            // remove the first header
            if (note.children.length > 0 && note.children[0].tagName === "HEADER") {
              note.children[0].remove();
            }
            const html = processXRef(null, note);
            instance.setContent(html);
          } 
        }).finally(() => {
          instance.enable();
          instance.show();
        });
      }
    }, function(instance) {
    });
  }
      let selectedAnnoteEl;
      const selectorForAnnotation = ( cell, annotation) => {
        let cellAttr = 'data-code-cell="' + cell + '"';
        let lineAttr = 'data-code-annotation="' +  annotation + '"';
        const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
        return selector;
      }
      const selectCodeLines = (annoteEl) => {
        const doc = window.document;
        const targetCell = annoteEl.getAttribute("data-target-cell");
        const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
        const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
        const lines = annoteSpan.getAttribute("data-code-lines").split(",");
        const lineIds = lines.map((line) => {
          return targetCell + "-" + line;
        })
        let top = null;
        let height = null;
        let parent = null;
        if (lineIds.length > 0) {
            //compute the position of the single el (top and bottom and make a div)
            const el = window.document.getElementById(lineIds[0]);
            top = el.offsetTop;
            height = el.offsetHeight;
            parent = el.parentElement.parentElement;
          if (lineIds.length > 1) {
            const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
            const bottom = lastEl.offsetTop + lastEl.offsetHeight;
            height = bottom - top;
          }
          if (top !== null && height !== null && parent !== null) {
            // cook up a div (if necessary) and position it 
            let div = window.document.getElementById("code-annotation-line-highlight");
            if (div === null) {
              div = window.document.createElement("div");
              div.setAttribute("id", "code-annotation-line-highlight");
              div.style.position = 'absolute';
              parent.appendChild(div);
            }
            div.style.top = top - 2 + "px";
            div.style.height = height + 4 + "px";
            div.style.left = 0;
            let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
            if (gutterDiv === null) {
              gutterDiv = window.document.createElement("div");
              gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
              gutterDiv.style.position = 'absolute';
              const codeCell = window.document.getElementById(targetCell);
              const gutter = codeCell.querySelector('.code-annotation-gutter');
              gutter.appendChild(gutterDiv);
            }
            gutterDiv.style.top = top - 2 + "px";
            gutterDiv.style.height = height + 4 + "px";
          }
          selectedAnnoteEl = annoteEl;
        }
      };
      const unselectCodeLines = () => {
        const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
        elementsIds.forEach((elId) => {
          const div = window.document.getElementById(elId);
          if (div) {
            div.remove();
          }
        });
        selectedAnnoteEl = undefined;
      };
        // Handle positioning of the toggle
    window.addEventListener(
      "resize",
      throttle(() => {
        elRect = undefined;
        if (selectedAnnoteEl) {
          selectCodeLines(selectedAnnoteEl);
        }
      }, 10)
    );
    function throttle(fn, ms) {
    let throttle = false;
    let timer;
      return (...args) => {
        if(!throttle) { // first call gets through
            fn.apply(this, args);
            throttle = true;
        } else { // all the others get throttled
            if(timer) clearTimeout(timer); // cancel #2
            timer = setTimeout(() => {
              fn.apply(this, args);
              timer = throttle = false;
            }, ms);
        }
      };
    }
      // Attach click handler to the DT
      const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
      for (const annoteDlNode of annoteDls) {
        annoteDlNode.addEventListener('click', (event) => {
          const clickedEl = event.target;
          if (clickedEl !== selectedAnnoteEl) {
            unselectCodeLines();
            const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
            if (activeEl) {
              activeEl.classList.remove('code-annotation-active');
            }
            selectCodeLines(clickedEl);
            clickedEl.classList.add('code-annotation-active');
          } else {
            // Unselect the line
            unselectCodeLines();
            clickedEl.classList.remove('code-annotation-active');
          }
        });
      }
  const findCites = (el) => {
    const parentEl = el.parentElement;
    if (parentEl) {
      const cites = parentEl.dataset.cites;
      if (cites) {
        return {
          el,
          cites: cites.split(' ')
        };
      } else {
        return findCites(el.parentElement)
      }
    } else {
      return undefined;
    }
  };
  var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
  for (var i=0; i<bibliorefs.length; i++) {
    const ref = bibliorefs[i];
    const citeInfo = findCites(ref);
    if (citeInfo) {
      tippyHover(citeInfo.el, function() {
        var popup = window.document.createElement('div');
        citeInfo.cites.forEach(function(cite) {
          var citeDiv = window.document.createElement('div');
          citeDiv.classList.add('hanging-indent');
          citeDiv.classList.add('csl-entry');
          var biblioDiv = window.document.getElementById('ref-' + cite);
          if (biblioDiv) {
            citeDiv.innerHTML = biblioDiv.innerHTML;
          }
          popup.appendChild(citeDiv);
        });
        return popup.innerHTML;
      });
    }
  }
});
</script>
</div> <!-- /content -->




</body></html>